Hi there, I've been searching the docs/api and I'm not completely certain on how to pass in a flag within a docker run method. I'm essentially trying to perform the following:
docker run -d -p 4444:4444 --shm-size=2g selenium/standalone-chrome:3.8.1-dubnium
Specifically, I'm trying to mount shm-size=2g to the container. How can I do this with dockerode?
Here is what I have:
createContainer(testName, sessionId) {
return new Promise((resolve, reject) => {
let useSeleniumPort = this.availablePorts.shift();
if (!useSeleniumPort) {
return reject(new Error('There were no available ports to run the docker container on'));
}
let containerCreateOpts = {
Volumes: {},
PortBindings: {},
Binds: [`${this.path}:${this.path}`]
};
containerCreateOpts.Volumes[this.charcoal_path] = {};
containerCreateOpts.PortBindings['4444/tcp'] = [{ HostPort: useSeleniumPort.toString() }];
this.log.info(`Creating a docker container for ${testName}`, { port: useSeleniumPort });
let container = this.docker.run(
`selenium/standalone-${this.browser}:${this.selenium_version}`,
[],
null,
containerCreateOpts,
(err) => {
if(err) {
this.log.error('An error has occurred when trying to make the docker container');
return reject(err);
}
}
);
container.on('container', container => {
this.log.info(`Docker container created for ${testName}`, { port: useSeleniumPort, id: container.id });
resolve({
seleniumPortNumber: useSeleniumPort,
containerId: container.id,
testName: testName
});
});
});
}
}
Any insight would be very much appreciated!
As dockerode uses Docker API to send requests, the better place to look for (possibly undocumented) options would be Docker API Reference:
I can see that https://docs.docker.com/engine/api/v1.32/#operation/ContainerCreate describes ShmSize option as part of HostConfig parameter.
A quick look at dockerode sources alongside with Docker API reference suggests that you need to pass HostConfig as a separate option,
like in the following:
containerCreateOpts = {
HostConfig: {
ShmSize: yournumber,
PortBindings: [],
}
};
Had a similar issue with BigBlueButton livestreaming container.
The HostConfig addition suggested by @DenSpirit was just what I was looking for. Works perfectly. Thanks!
Most helpful comment
As dockerode uses Docker API to send requests, the better place to look for (possibly undocumented) options would be Docker API Reference:
I can see that https://docs.docker.com/engine/api/v1.32/#operation/ContainerCreate describes ShmSize option as part of HostConfig parameter.
A quick look at dockerode sources alongside with Docker API reference suggests that you need to pass HostConfig as a separate option,
like in the following: