Container commands
Container commands enable us to start, stop, and restart containers, execute commands upon them, and also kill them.
exec
Throughout the book, we have executed commands using the Docker exec
command. Docker Compose also provides this functionality. The difference is that instead of running the exec
command directly to a container on Compose, we specify the service to execute upon. The command then will be routed to the service’s underlying container:
$ docker compose exec task-manager ls go.mod go.sum main.go
If we check the existing containers, we will not see any extra containers provisioned:
$ docker ps -a CONTAINER ID IMAGE &...