Docker-compose can be used to deploy simple applications, it gives ability to start set of dependent containers or services as a whole application. It is simple to use and configure.
There are alternatives like docker swarm or Kubernetes which are suitable for complex and enterprise applications.
Docker compose provides simplicity for deploying simple applications. When server is restarted docker containers will not start at automatically. This can be solved by creating custom systemd service.
- Write docker-compose.yml file with all services/components, below is the django app example taken from docker documentation.
- You can start web and db application using docker-compose up
# will bring up all services in docker-compose.yml docker-compose up -d # pass yml file with -f flag docker-compose up -f application.yml
- -d flag will start docker services in daemon/background mode
- Write systemd service in /etc/systemd/system/myapp.service
- Now you have created myapp service, enable it and start the service. Enabling service will make sure to start this service at server startup.
# will enable service to start at server bootup systemctl enable myapp # start service ( Executes ExecStart command ) systemctl start myapp
This way you can make sure your docker-compose service stays up and running after server restart.