Docker Compose
Understand how docker compose works.
Use to startup multiple Docker containers at the same time.
compose.yaml
All configurations here are the same from the docker run
command. Currently, I'm showing docker compose v2 instead of v1. So some syntax might be different due to some syntax already deprecated.
A default network is created for all the composed containers. that means all containers that are created will be automatically added to that network.
Additional;
- If you want to specify
-it
incompose.yaml
, you will have to specify these two fields (mandatory)stdin_open: true
- This service needs an open input connectiontty: true
- Attaching this terminal-it
=stdin_open
+tty
- If you want to override the
Dockerfile
entrypoint, you can specifyentrypoint
withincompose.yaml
, then it will override the entrypoint inDockerfile
that is defined.
Commands
Use docker compose
instead of docker-compose
.
List containers
Build or rebuild containers
It only builds containers without starting it.
Create and start containers
Up = Build/rebuild + start
Execute a command in a running container
By default, it will allocate a TTY by default, so you can straight away get an interactive prompt from this command docker compose exec apiservice bash
.
Display service log output
Stop services
Stop running containers without removing them. The services can be started again with docker compose start
.