11/23/2021»»Tuesday

Instal Docker Compose Ubuntu

At the end of this tutorial, you learned about the basic concepts of Docker compose, its installation on Ubuntu 14.04 and its usage to create and manage new containers on docker-compose. You can also deploy multiple applications in no time using the docker-compose. We hope you found this article helpful as a starting point on docker. See full list on docs.docker.com.

What is Docker Compose?

DockerCompose is a command-line tool for defining and running multi-container applications. With Docker compose, you can run multiple containers as a single service. The containers are still isolated, but they can interact with each other. With Docker compose, you get the benefits of single-host deployment, great security, ease of setup and configuration which leads to really high productivity and efficiency.

For example, if you have an application that requires an Apache web server and MariaDB database, you can create a docker-compose.yaml file that can run both the containers as a service without the need to start each one separately.

Install Docker Compose Ubuntu 20

What is Compose File?

Docker Compose uses a YAML (docker-compose.yaml) file for defining configure application services, networks and volumes. The default path for a Compose file is ./docker-compose.yaml. It contains a service definition which configures each container started for that service. With a single command, you can create and start all the services from your YAML configuration file.

In this tutorial, we will show you how to install and use Docker Compose on Ubuntu 20.04 18.04.

Prerequisites

  • A server running Ubuntu 20.04 with Docker installed.
  • A root password is configured on your server.

Note: Please refer to my guide on How to Install and Use Docker for a more detailed reference on Docker.

Install Docker Compose Ubuntu

Docker Compose available in a single binary file. So you don’t need to install it from the Ubuntu repository. At the time of writing this article, the latest version of Docker Compose is 1.28.0. Before downloading the Docker Compose, I would recommend visiting the Docker Compose download page for the latest available version.

First, install the curl command-line tool with the following command:

Next, pick the latest version of DockerCompose from their download page and run the following command:

After the successful download, set the execution permission to the downloaded binary with the following command:

Next, verify the installed version of DockerCompose with the following command:

Output:

Create a docker-compose.yml File

In this section, we will create a docker-compose.yaml to demonstrate how to use Docker Compose. We will then create a web server environment using the Nginx image.

First, create a project directory inside your home directory:

Next, create a webapp directory for Nginx document root:

Next, create an index.html file inside the webapp directory:

Add the following codes:

Save and close the file then change the directory to your project and create a docker-compose.yaml file:

Add the following lines:

Save and close the file when you are finished.

Run Docker Compose

At this point, docker-compose.yaml is ready for use. Now, you can use “docker-compose up” command to pull the necessary Docker images, create a container for the web service, and run the containerized environment in background mode:

You should see the following output:

You can now verify all running container with the following command:

You should see all information about your running container in the following output:

Docker Compose Basic Commands

In this section, we will show you some most commonly used Docker Compose Commands to manage and interact with your containerized environment.

To start all services, run the following command:

To stop all services, run the following command:

To pause and unpause all services, run the following command:

To check the version of Docker Compose, run the following command:

To scale a service, run the following command:

To check the logs produced by containers, run the following command:

Conclusion

In the above post, you learned how to install and use Docker Compose on Ubuntu 20.04. I hope you can now deploy and scale your application easily with Docker Compose.

In this short post I'm giving you two lines of code so you can easily install docker(opens new window) and docker-compose(opens new window)

Let's get to it!

Instal Docker Compose Ubuntu

Install Docker Compose Ubuntu 16

# Install Docker

First we are going to install docker.

Ok ok, this is rather a code block than a one-liner, but still nice. This will make sure you can run composer, setup the ppa repository so you can install and update it, and finally install docker.

If you want to run docker as non root users you will need to run the linux post install steps(opens new window). Here is another one-liner to do so - since you are using ubuntu and all 😉

And that's it for docker. Let's go to docker-compose.

# Install Docker Compose

Here is the one-liner to install docker-compose.

And that's it. Now you should have docker and docker-compose installed 😁

Most Viewed Posts