I believe the difference might be because the second command does shell processing while the first does not. Per the official documentation, there are the exec
and shell
forms. Your first command is an exec
form. The exec
form does not expand environment variables while the shell
form does. It is possible that by using the exec
form the command is failing due to its dependence on shell processing. You can check this by running docker logs CONTAINERID
Your second command, the shell form, is equivalent to -
CMD /etc/init.d/nullmailer start ; /usr/sbin/php5-fpm
Excerpts from the documentation -
Note: Unlike the shell form, the exec form does not invoke a command shell. This means that normal shell processing does not happen. For example, CMD [ "echo", "$HOME" ]
will not do variable substitution on $HOME
. If you want shell processing then either use the shell form or execute a shell directly, for example: CMD [ "sh", "-c", "echo", "$HOME" ]
.
Purpose of the volumes
key
It is there to create named volumes.
If you do not use it, then you will find yourself with a bunch of hashed values for your volumes. Example:
$ docker volume ls
DRIVER VOLUME NAME
local f004b95d8a3ae11e9b871074e9415e24d536742abfe86b32ffc867f7b7063e55
local 9a148e167e1c722cbdb67c8edc36f02f39caeb2d276e9316e64de36e7bc2c35d
With named volumes, you get something like the following:
$ docker volume ls
local projectname_someconf
local projectname_otherconf
How to create named volumes
The docker-compose.yml
syntax is:
version: '2'
services:
app:
container_name: app
volumes_from:
- appconf
appconf:
container_name: appconf
volumes:
- ./Docker/AppConf:/var/www/conf
volumes:
appconf:
networks:
front:
driver: bridge
This something like above shown named volumes.
How to remove volumes in bulk
When you have a bunch of hashes, it can be quite hard to clean up. Here's a one-liner:
docker volume rm $(docker volume ls |awk '{print $2}')
Edit: As @ArthurTacca pointed out in the comments, there's an easier to remember way:
docker volume rm $(docker volume ls -q)
How to get details about a named volume
Now that you do not have to look up hashes anymore, you can go on it and call them by their … name:
docker volume inspect <volume_name>
# Example:
$ docker volume inspect projectname_appconf
[
{
"Name": "projectname_appconf",
"Driver": "local",
"Mountpoint": "/mnt/sda1/var/lib/docker/volumes/projectname_appconf/_data"
}
]
Sidenote: You might want to docker-compose down
your services to get a fresh start before going to create volumes.
In case you are using Boot2Docker/ Docker Machine, you will have to docker-machine ssh
and sudo -i
before doing a ls -la /mnt/…
of that volume – you host machine is the VM provisioned by Docker Machine.
EDIT: Another related answer about named volumes on SO.
Best Answer
When you create a docker-compose.yml like this:
And do not specify a default network configuration, the docker-compose actually creates a custom default network by the name of the folder you are running the
docker-compose up
command:Then the container is created and joins this custom network, and the external link is set when the container joins the network. You can inspect the recently created container and see for yourself:
The
docker-compose up
actually translates to something like this in pure docker commands: