Choose a different version or distribution
Before we begin talking about how to install and use Docker Compose on Debian 10 Linux, let's briefly understand – What is Docker Compose?
Docker is a containerization technology that enables you to easily develop, test, and deploy programs as portable, self-sufficient containers that can run virtually anywhere.
You may define and orchestrate multi-container Docker applications using the tool known as Docker Compose. The containers, networks, and volumes of the application are configured using a YAML file.
Compose can be used for a number of purposes. The most common use cases for Docker Compose are local development, automated testing, and single host application deployments.
In this tutorial, you will install the most recent version of Docker Compose on Debian 10, Buster. We will also look at the core concepts and commands of Docker Compose.
Before you begin, ensure that you have met the following requirements:
- You are logged in as a user with sudo privileges.
- Docker is installed on your Debian 10 system.
Installing Docker Compose on Debian 10
It's possible that the official Debian 10 repositories won't always have the most recent version of Docker Compose installation package. The recommended method is to install Docker Compose from the Docker GitHub repository.
The latest stable version of Docker Compose is version
2.15.0 as of the time this tutorial was written. Visit the Compose repository release page on GitHub to see if a new version is available before downloading the Compose binary.
To install Docker Compose's latest version on Debian 10, follow these steps:
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2) To make the Compose binary executable, use
sudo chmod +x /usr/local/bin/docker-compose
3) Use the command that prints the Compose version to confirm the installation:
You will get an output like below:
Output docker-compose version 1.23.1, build b02f1306
Getting Started with Docker Compose
We will demonstrate how to set up a local WordPress development environment using Docker Compose in this part.
Make a directory for the project, then navigate there:
mkdir wordpress_app && cd wordpress_app
Open a text editor, and make a file called
Copy and paste the following text:
version: '3.7' services: db: image: mysql:8.0 command: --default-authentication-plugin=mysql_native_password restart: always volumes: - db_data:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: wordpress wordpress: image: wordpress restart: always volumes: - ./wp_data:/var/www/html ports: - "8080:80" environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_USER: root WORDPRESS_DB_PASSWORD: password depends_on: - db volumes: db_data: wp_data:
Let us go through the code line by line.
The version of the Compose file is specified in the first line. The Compose file format is available in several variations, each of which supports a particular Docker release.
Next, we are defining the
db services. When Docker Compose is executed, each service creates an individual container.
- The image has been set to
mysql:8.0image. If the image is missing, Compose will retrieve it from the public Docker Hub repository. The line starting with
commandtakes precedence over the default command.
- If the container stops responding, Compose is instructed to restart it by the
- To persist the database, the container will use the named volume
- Defines the
mysql:8.0image's environment variables.
wordpressimage is used.
- Mounts the host's
/var/lib/mysqlwithin the container.
- Forwards the container's exposed port
80to the host machine's port
- Defines the
wordpressimage's environment variables.
- The dependency between the two services is defined by the
depends_oncommand. In this case, the
dbwill launch before
Run the following command to launch the WordPress stack from the project directory:
The output should resemble this:
... ] /usr/sbin/mysqld: ready for connections. Version: '8.0.18' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL. db_1_99946702ac7e | 2019-12-15T21:37:29.109255Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060 ...
wp_data directory will be created in your project directory by Docker Compose, which will also start the containers and pull the images.
In your browser, type
http://0.0.0.0:8080/ to access the standard WordPress installation screen.
The WordPress application is now operational, and you may begin working on it.
CTRL+C to stop Compose.
-d option, you can also start the Compose in detached mode:
docker-compose up -d
Use the following command to view the running Docker containers:
Output Name Command State Ports ------------------------------------------------------------------------------------------------------ wordpress_app_db_1_99946702ac7e docker-entrypoint.sh --def ... Up 3306/tcp, 33060/tcp wordpress_app_wordpress_1_a428d8408817 docker-entrypoint.sh apach ... Up 0.0.0.0:8080->80/tcp
When Compose is operating in detached mode, use the following to stop the services:
down option to completely remove the containers:
--volumes switch removes the data volumes as well:
docker-compose down --volumes
Uninstalling Docker Compose
If you want to uninstall Docker Compose, just remove the binary by typing:
sudo rm /usr/local/bin/docker-compose
We hope this detailed guide helped you understand how to install and use Docker Compose on Debian 10 Linux.
Download the binary, place it in a directory on the system path, and make it executable to install Docker Compose on a Debian 10 system.
If you have any queries, feel free to post a comment below, and we'll be happy to answer them.