SIGN IN / UP
    opened image

    List of important commands for working with Docker-compose

    Docker-compose is a powerful tool for creating and managing Docker containers. This tool allows you to create, run, and manage multiple containers that interact with each other. In this article, we will look at several commands that can be useful when working with Docker-compose.

    So let's get started.
     

    1. Commands for managing containers:
    • docker-compose up: to start all containers defined in the docker-compose.yml file. 

           For example, the command "docker-compose up" will start all containers from the docker-compose.yml file in the current directory.

    • docker-compose down: to stop and remove all containers defined in the docker-compose.yml file. 

           For example, the command "docker-compose down" will stop and remove all containers that were started using the docker-compose.yml file.
     

    1. Commands for managing services:
    • docker-compose ps: to display a list of running containers and their statuses. 

           For example, the command "docker-compose ps" will show all running containers from the docker-compose.yml file.
    List of important commands for working with Docker-compose

    • docker-compose up -d [SERVICE]: to start a specific service from the docker-compose.yml file. 

           For example, the command "docker-compose up nextcloud" will start only the nextcloud container from the docker-compose.yml file that was stopped.

    List of important commands for working with Docker-compose-1List of important commands for working with Docker-compose-2

    1. Commands for managing images:
    • docker-compose pull: to download all images defined in the docker-compose.yml file. For example, the command "docker-compose pull" will download all images specified in the docker-compose.yml file.
    • docker-compose build: to build images defined in the docker-compose.yml file. For example, the command "docker-compose build" will build all images specified in the docker-compose.yml file.
    1. Commands for managing logs:
    • docker-compose logs: to view the logs of all containers defined in the docker-compose.yml file. For example, the command "docker-compose logs" will display the logs of all containers from the docker-compose.yml file.

    List of important commands for working with Docker-compose-3

    • docker-compose logs [SERVICE]: to view the logs of a specific service from the docker-compose.yml file. For example, the command "docker-compose logs nextcloud_db" will display the logs of only the database container from the docker-compose.yml file.

    List of important commands for working with Docker-compose-4

    1. Commands for managing running containers:
    • docker-compose stop: to stop all containers defined in the docker-compose.yml file, but without removing them. For example, the command "docker-compose stop" will stop all containers from the docker-compose.yml file.

    List of important commands for working with Docker-compose-5

    • docker-compose start: to start all stopped containers defined in the docker-compose.yml file. For example, the command "docker-compose start" will start all stopped containers from the docker-compose.yml file.


     

     

    • docker-compose up --force-recreate forces Docker Compose to recreate containers even if their configuration or image has not changed. This means that Compose will stop and remove existing containers for the services specified in the docker-compose.yml file, and then create new containers from scratch using the latest versions of the images defined in the file. Using the --force-recreate option is useful in situations where you have made changes to the docker-compose.yml file that affect the container configuration, such as environment variables or port mapping.

     

     

     

    1. Commands for managing networks:

     

    • docker-compose network ls: to display a list of networks defined in the docker-compose.yml file if any. You can also use the docker network ls command.

    List of important commands for working with Docker-compose-6

    • docker-compose network create [NETWORK]: to create a new network in the docker-compose.yml file. For example, the command "docker-compose network create frontend" will create a new network named frontend in the docker-compose.yml file.
    • docker-compose network rm [NETWORK]: to remove a network defined in the docker-compose.yml file. For example, the command "docker-compose network rm frontend" will remove a network named frontend from the docker-compose.yml file.
    1. Commands for managing environment variables:
    • docker-compose config: to check the correctness of the docker-compose.yml file and display all environment variables defined in it. For example, the command "docker-compose config" will check the correctness of the docker-compose.yml file and show all environment variables defined in it.

    List of important commands for working with Docker-compose-7

    • docker-compose exec [SERVICE] [COMMAND]: to execute a command inside a container defined in the docker-compose.yml file. For example, the command "docker-compose exec nextcloud ls" will execute the "ls" command inside the nextcloud container defined in the docker-compose.yml file.

    List of important commands for working with Docker-compose-8

    1. Commands for managing volumes:
    • docker-compose volume ls: to display a list of all volumes defined in the docker-compose.yml file. For example, the command "docker-compose volume ls" or "docker volume ls" will show all volumes defined in the docker-compose.yml file.

    List of important commands for working with Docker-compose-9

    • docker-compose volume create [VOLUME]: to create a new volume defined in the docker-compose.yml file. For example, the command "docker-compose volume create db_data" will create a new volume named db_data in the docker-compose.yml file.
    • docker-compose volume rm [VOLUME]: to remove a volume defined in the docker-compose.yml file. For example, the command "docker-compose volume rm db_data" will remove a volume named db_data from the docker-compose.yml file.


    In this article, we have covered the basic commands for working with Docker Compose, such as starting and stopping containers, creating networks and volumes, and managing volumes. Familiarizing yourself with these commands will help you use Docker Compose more effectively when developing and deploying applications in containers.