the description for the Volumes key of the options passed to /containers/create as documented here: https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/ indicates it should receive:
"An object mapping mount point paths (strings) inside the container to empty objects."
what? empty objects? what does that mean? I don't see from the source of dockrode how to make the call. if I currently do this in the CLI: -v ~/db:/data, would I:
Volumes: {'~/db': '/data'}
or...
Volumes: {'~/db': { ...what?... }}
there are no examples for guidance. how do I do this?
apocas, thanks for replying but I'm afraid that reading the test doesn't make this any clearer for me. the one line that perhaps would be relevant is expect(info.Name).to.equal(testVolume.Name); but that tells me that info (perhaps the value passed into Volumes:?) should contain a Name attribute... so... Volumes: {'~/db': {Name: ???}} - help?
For the next person who hits this on search:
Volumes (in this context) are non-copy-on-write directories inside the container. What we want here are 'binds':
var options = { Binds: ['/var/run/docker.sock:/var/run/docker.sock', '/opt/app:/home/mysource'] }
I still don't get it. From the command line, I can enter a -v argument like this and it works.
docker run -v myvolume:/mypath ...
...where myvolume is a volume I created with docker create volume myvolume. And I'm expecting it to get mounted at /mypath within the container.
So, how do I accomplish the exact same thing as above in dockerode?
What do I need to specify for Volumes? What do I need to specify for HostConfig.Binds?
@wyckster did you manage to figure this out?
@EdByrnee The confusion was about finding documentation for the schema of the parameter object that is passed to createContainer. And how to specify the volumes / binds.
docker.createContainer({
Volumes: { /* Here? */ },
HostConfig: {
Binds: [ /* Here ? */ ]
},
Binds: [ /* or Here? */ ]
})
If I recall correctly the solution is that you don't specify HostConfig.Binds, you just specify Binds.
Incidentally, I switched to calling out to docker-compose externally. Sadly I dropped dockerode entirely. :(
But Docker-compose is proving to be more useful anyway.
I can add to this: If you don't need any HostConfig options, it is fine to use Binds at the root of the options. If you specify other options inside HostConfig, you must move Binds inside HostConfig, like this:
const createOptions = {
Tty: true,
ExposedPorts: { '3333/tcp': {} },
PortBindings: { '3333/tcp': [{ 'HostPort': '3333' }] },
HostConfig: {
AutoRemove: true,
Binds: [
`${configDir}:/var/tmp/whatever`
]
}
}
This works, at least for now.
@DonMartin76 I followed your solution but not work now :( By the way, isn't PortBindings a property of HostConfig? Can we just put it at the root of the options?
Most helpful comment
For the next person who hits this on search:
Volumes (in this context) are non-copy-on-write directories inside the container. What we want here are 'binds':