My docker containers are build with docker-compose and I automatically start them container on my CentOS 7 system using derivatives from the documentation example::
[Unit]
Description=condb container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker start -a condb
ExecStop=/usr/bin/docker stop -t 2 condb
[Install]
WantedBy=local.target
Everything is working fine except for the fact that every time I want to change the container, I stop the services, run docker-compose up
to create the container and then start the services, I forget that up
already starts the containers.
I can adapt my script around this to stop the containers after running docker-compose
, but starting/shutdown takes time and I wonder if there is a way to just create the container without starting it (the build
command just builds, up
does build-create-start according to its help)?
Best Answer
The sources for docker compose already have a
create
command, but it is not in 1.5.2 yet, nor documented on the website. You can of course try and install from the github source and get the latest (unreleased) features.Alternatively you can try and change your
systemd
files to not start the individual containers usingdocker
, but run docker-compose on the YAML files:then you can just stop using
systemctl stop ...
, change thedocker-compose.yml
file, and start usingsystemctl start ...
. I am not sure though if the correct restarting is done in case one of the containers in the compose setup goes down.