Menu

Poland

GRANDMETRIC Sp. z o.o.
ul. Metalowa 5, 60-118 Poznań, Poland
NIP 7792433527
+48 61 271 04 43
info@grandmetric.com

Sweden

Drottninggatan 86
111 36 Stockholm
+46 762 041 514
info@grandmetric.com

UK

Grandmetric LTD
Office 584b
182-184 High Street North
London
E6 2JA
+44 20 3321 5276
info@grandmetric.com

US Region

Grandmetric LLC
Lewes DE 19958
16192 Coastal Hwy USA
EIN: 98-1615498
+1 302 691 94 10
info@grandmetric.com

  • en
  • pl
  • se
  • docker-compose configuration

    Design & Configure

    docker-compose configuration

    What is docker-compose?

    Docker-compose is a useful tool for orchestrating multi-container Docker applications. It allows you to run applications based on a YAML file. These files are a list of instructions specifying the parameters of the applications to be launched.

    In our example, we will run two containers – a MySQL database and a basic WordPress web application.

    Docker build files might look like this:


    version: '3.3'

    services:
       db:
          image: mysql:5.7
          volumes:
             - db_data:/var/lib/mysql
          restart: always
          environment:
             MYSQL_ROOT_PASSWORD: somewordpress
             MYSQL_DATABASE: wordpress
             MYSQL_USER: wordpress
             MYSQL_PASSWORD: wordpress

       wordpress:
          depends_on:
             - db
          image: wordpress:latest
          ports:
             - "8000:80"
          restart: always
          environment:
             WORDPRESS_DB_HOST: db:3306
             WORDPRESS_DB_USER: wordpress
             WORDPRESS_DB_PASSWORD: wordpress
             WORDPRESS_DB_NAME: wordpress
          volumes:
             db_data: {}

     

     

    How to manage a multi-container application with docker-compose?

    We can use some basic docker-compose commands to manage containers:

    Build or rebuild websites

     

    docker-compose build

     

    Create and run containers

     

    docker-compose up

    docker-compose up

     

    As you can see, the containers have been launched and the logs printed on the console. To run in the background, use the -d parameter.

     

    Run a one-time command on the website

     

    docker-compose run
    ex: docker-compose run wordpress

    For example, you can print the Debian version of the WordPress container.

    docker-compose run wordpress

     

    Show list of running containers

    docker ps

    The docker ps command shows:

    • container ID,
    • name and version of the image,
    • how long ago the container was created,
    • status,
    • ports and container name.

     

    docker ps komendy docker-compose

     

    Print a list of information about running containers from the current docker-compose.yaml file

    docker-compose ps

    docker-compose ps wordpress

     

    Show all logs in the container since its launch

    docker logs <service>

    docker logs service

     

    Stop and delete containers, networks, volumes and images created with the “up” command

    docker-compose down

    docker-compose down

     

    Kill one or more running containers

    docker kill <container_id>

    docker kill service

     

    Show image list

    docker images

    docker images

     

    Execute the command in a running container

    docker exec <service> <bash_command>

    docker-compose run wordpress

     

    Delete all unused data

    docker system prune

    docker system prune img

    Useful command combinations

    Kill all running containers

    docker kill $(docker ps -q)

    Stop all running containers

    docker stop $(docker ps -q)

    Delete all images

    docker rmi $(docker images -q)

    Remove all containers

    docker rm $(docker container ps -q)

     

    Summary

    Docker-compose is a useful and easy tool for managing multiple containers. You can decide how containers are separated, what resources they can use and how they communicate with each other. You can also set what happens if the status of one of the containers changes. This feature allows you to automatically restore your system state.

     

    More Docker configurations

    dockerfile

     

    Author: Mateusz Sobkowiak
     
    Grandmetric