Docker Compose useful commands

|

Docker Compose is awesome!

  • it allows you to define and run multi-container Docker applications.
  • It makes it easier to manage multiple containers by defining them in a single YAML file, which can be used to create, start, stop, and delete the containers.
  • and some other things that I should probably list but seriously it’s amazing.

docker compose up

The docker compose up command is used to start the containers defined in the YAML file. If the containers do not exist, they will be created. If the containers already exist, they will be started. if they are already started, it will just do nothing, unless something was edited in the docker-compose.yml file, in which case it will recreate the container.

docker compose up

This command will start all the containers defined in the YAML file. If you want to start a specific container, you can use the following command:

docker-compose up <container-name>

docker compose down

The docker compose down command is used to stop and remove all the containers defined in the YAML file. you can’t bring down a single container, it has to be all of them in the YAML file.

docker-compose down

docker compose logs

The docker compose logs command is used to view the logs of the containers defined in the YAML file.

docker compose logs

This command will display the logs of all the containers defined in the YAML file. If you want to view the logs of a specific container, you can use the following command:

$ docker compose logs -f <container-name>

docker compose ps

The docker-compose ps command is used to list all the containers defined in the YAML file and their status.

docker compose ps

this will give an output like this :

NAME                COMMAND             SERVICE             STATUS              PORTS
mycoolapp          "/init"             mycoolapp          running             80/tcp, 3000->3000/tcp

docker compose build

The docker compose build command is used to build the images of the containers defined in the YAML file.

docker compose build

docker compose exec

The docker compose exec command is used to execute a command inside a running container.

docker compose exec mycoolapp somecommand

This command will execute the somecommand inside the mycoolapp container.

e.g. to get to bash and run arbitrary commands inside you mycoolapp container:

docker compose exec mycoolapp bash

docker compose restart

The docker compose restart command is used to restart the containers defined in the YAML file.

docker compose restart

do you need more explanation on any of these? let me know in the comments!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *