5

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)?

1

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 using docker, but run docker-compose on the YAML files:

[Service]
Restart=always
ExecStart=/opt/util/docker-compose/bin/docker-compose -f /opt/docker/mongo/docker-compose.yml up --no-recreate
ExecStop=/opt/util/docker-compose/bin/docker-compose -f /opt/docker/mongo/docker-compose.yml stop

then you can just stop using systemctl stop ..., change the docker-compose.yml file, and start using systemctl start .... I am not sure though if the correct restarting is done in case one of the containers in the compose setup goes down.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.