CHEATSHEET: Docker Compose - Basic Syntax and Concepts
published on Sun May 17 2020Configuarion
version- specify which version of docker compose file format to be usedservices- lists the different services to be started for the app. Each service definition contains configuration that is applied to each container started for that serviceimage- specifies the image to start the container frombuild- configuration options that are applied at build timeports- expose ports from the container to the host machinerestart- sets the restart policy. Possible values are:"no"- no restarts of container. This is the default. The double-quotes are requiredalways- restarts if container stops for ANY reasonon-failure- restarts if container stopped with an error codeunless-stopped- restarts unless the container was manually stopped
CLI Commands
docker-compose up- builds, (re)creates, starts, and attaches to containers for a service. Accepted flags are:--build- build images before starting containers-d, --detach- run containers in the background
docker-compose down- stops containers and removes containers, networks, volumes, and images created by updocker-compose ps- lists the running containers initialized bydocker-composewith the currentdocker-compose.ymlfile