Docker Community Forums

Share and learn in the Docker community.

Docker remote API connect to volume container

(Alex Walker) #1

I have everything working nicely from the terminal.
I have created a volume container called S_ENABLED
I have created a standard container called nginxserver
I am starting nginxserver with a --volumes-from to S_ENABLED. This works perfectly.
However I want to start nginxserver from the remote API binding it to S_ENABLED.
Below I have put my commands for creating the containers on the command line, which work, and I have included my URL hits (using curl) to try and create them using the remote API, however it inside the nginxserver the S_ENABLED volume doesnt seem to be mounted. Any help would be appreciated.

Creating S_ENABLED from the command line

docker run -v /home/vagrant/docker/examples/sites-enabled/:/etc/nginx/sites-enabled --name S_ENABLED centos:7 true

Creating S_ENABLED from API:

curl -X POST -H "Content-Type: application/json" -d '{ "Cmd": "true", "Volumes": {"/etc/nginx/sites-enabled": {}}, "Image":"centos:7"}'

as I understand it the

"Volumes": {"/etc/nginx/sites-enabled": {}}

is the path INSIDE the container that is going to be bound to the S_ENABLED volume container.


curl -X POST -H "Content-Type: application/json" -d '{ "Binds": ["/home/vagrant/docker/examples/sites-enabled/:/etc/nginx/sites-enabled:rw"] }'[id]/start

My understanding of the above is the Binds is the from:to:rw i.e from on the host, to in the container:[read/write permissions]

Creating nginxserver from the command line:

docker run -d -p 80:80 --volumes-from S_ENABLED --name nginxserver nginx:latest

create nginx container, to do a Volumes-from I do:

curl -X POST -H "Content-Type: application/json" -d '{"Image":"nginx:latest","VolumesFrom": ["S_ENABLED"] }'

and to start it I do:

curl -X POST -H "Content-Type: application/json" -d '{"PortBindings":{ "80/tcp": [{ "HostPort": "80" }] }}'

I get no errors, however when I do:

docker exec -it nginxserver bash

and navigate to /etc/nginx/sites-enabled the contents of the host location directory (/home/vagrant/docker/examples/sites-enabled/) is not shown, so either I am setting up the volume container incorrectly, or I am connecting to the volume container from nginxserver incorrectly. The documentation on this feels a bit sparse, could anyone advise me where i am going wrong?