Docker is an open-source program that eases the processes of creating, deploying, and running of any application. It also provides a light-weight workplace for executing your applications. Docker already has a bundle of packages and libraries that are required for the deployment of any application. Any application can be transformed from a developer’s laptop to the real testing environment and then into production. Docker made this thing very handy to do. In such a case, the developer knows that all of the application dependencies are already present within the container, that’s why he doesn’t worry about its execution on the production server. This program has its process and network space and layered union system of files. Go programming language is utilized to fulfill this purpose.
Three ruling components of Docker are:
- Docker container
- Docker server
- Docker client
Now let’s talk about Docker compose.
What is Docker Compose?
- A user can use Docker Compose for starting all of the services with a single command.
- YAML files are used in all Docker Compose folders.
- Docker Compose is a tool that permits users to execute multiple containers as a service. Containers operate in isolation here, but they do communicate with one another.
The functionality of Docker Compose:
Compose is a Docker application that permits you for defining and executing multi-containers of Docker applications. You configure your application’s services with Compose using a YAML file. You can also start and build all of the services from your setup with a single command. It’s compatible with all environments, including staging, production, development, as well as constant integration workflows.
Compose has commands for controlling your application’s entire lifecycle:
- Activate, deactivate, and restore services
- Stream the output of operating services’ log files.
- View the status of currently active services.
- Activate a service with a one-time command.
- Moving a composition between environments are features of Compose that make it efficient.
- Executing and preserving multiple isolated environments on a single host.
That’s all about Docker compose. Now, let’s start its installation guide on Ubuntu 20.04. Firstly, ensure that you are using the terminal as a ‘superuser’.
Installing Docker Composer on Ubuntu 20.04
Step 1: Open the terminal by pressing ‘CTRL+ALT+T’ or search it manually in the activities and update the packages list.
$ sudo apt update
Step 2: Utilize the curl command to download the compose package and store it in your local file.
$ sudo curl -L “https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s) -$(uname -m)” -o /usr/local/bin/docker-compose
Step 3: Change the file permissions, and make the file executable.
$ sudo chmod +x /usr/local/bin/docker-compose
Step 4: Check the docker version to confirm its installation on your system.
$ docker-compose --version
Using Docker Compose:
Step 1: First of all, we need to create a new directory of the project.
$ mkdir my_app $ cd my_app
Step 2: Open up the text editor, and add the following content in their script.
$ nano docker-compose.yml
version: '3' services: db: image: mysql:5.7 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:
Write-out the content by pressing CTRL+O and then exit.
Step 3: Start your Word press application by utilizing the given command.
$ docker-compose up
You have seen a complete tutorial for Docker Compose installation on Ubuntu 20.04.
The Best Linux Tutorials Website