Skip to content

Commit acf203b

Browse files
committed
Added text file read from volume
1 parent 38c93fe commit acf203b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ Volumes listed in `iobBackup` are tagged for inclusion in ioBroker backup routin
180180
-->
181181

182182
## Changelog
183+
### **WORK IN PROGRESS**
184+
- (@GermanBluefox) Added text file read from volume
185+
183186
### 0.1.3 (2025-10-09)
184187
- (@GermanBluefox) Split the docker manager into pure docker commands and monitoring of own containers
185188

src/lib/DockerManager.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,32 @@ export default class DockerManager {
19151915
}
19161916
}
19171917

1918+
/** Read a text file from a volume */
1919+
async volumeFile(volumeName: string, filePath: string): Promise<string | null> {
1920+
try {
1921+
// Execute `docker run --rm -it -v {volumeName}:/data alpine cat /data/{filePath}
1922+
const result = await this.containerRun({
1923+
image: 'alpine',
1924+
name: `iobroker_temp_cat_${Date.now()}`,
1925+
removeOnExit: true,
1926+
tty: false,
1927+
stdinOpen: false,
1928+
command: ['cat', join('/data', filePath).replace(/\\/g, '/')],
1929+
mounts: [{ type: 'volume', source: volumeName, target: '/data', readOnly: true }],
1930+
});
1931+
if (!result || result.stderr) {
1932+
this.log.error(
1933+
`Cannot read file ${filePath} in volume ${volumeName}: ${result?.stderr || 'unknown error'}`,
1934+
);
1935+
throw new Error(result?.stderr);
1936+
}
1937+
return result.stdout || '';
1938+
} catch (e) {
1939+
this.log.error(`Cannot read file ${filePath} in volume ${volumeName}: ${e.message}`);
1940+
throw e;
1941+
}
1942+
}
1943+
19181944
/**
19191945
* Create a volume
19201946
*

0 commit comments

Comments
 (0)