Home Linux ServerTools Install and use Docker Compose on Ubuntu 22.04

Install and use Docker Compose on Ubuntu 22.04

by Thạch Phạm
Published: Last Updated on
A+A-
Reset

How to install and use Docker Compose on Ubuntu 22.04 with 2 steps.

Introduction

Docker compose is a tool to define and run multi-containers for Docker applications. With compose, you use the YAML file to configure the services for your application. Then use the command to create and run from those configs. The steps to use are also quite simple, as follows:

  • Declare the app’s environment in Dockerfile.
  • Declare the services needed to run the application in the docker-compose.yml file.
  • Run docker-compose up to start and run the app.

In this tutorial, AZDIGI will show you how to install Docker compose and create a new application using Docker compose on Ubuntu 22.04.

Prerequisites before installing Docker compose

  1. You must have SSH access
  2. The server must have Docker pre-installed.

Implementation Guide

Step 1: Install Docker Compose

  • To install the latest version of Docker Compose from the GitHub repository, use the following command:
AZDIGI Tutorial
sudo curl -L https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
    
  • Permissions for the downloaded file
AZDIGI Tutorial
sudo chmod +x /usr/local/bin/docker-compose
    
  • Check results after installation
AZDIGI Tutorial
docker-compose --version
    
CleanShot 2022 05 14 at 16.37.37

So Docker Compose has been successfully installed and you can start running containers.

Step 2: How to use Docker Compose

Docker Compose allows you to use YAML files to define multiple container applications. With the YAML file, you can run, build and configure all the containers.

  • Create a project folder and move into that project folder, for example:
AZDIGI Tutorial
mkdir docker-project 
cd docker-project 
    
  • Next, you need to create a YAML file. For example, I will create a yaml file for hello world.
AZDIGI Tutorial
sudo nano docker-compose.yml
    

Add the below content to the created file

version: '3.9'
services:
   hello-world:
      image:
         hello-world:latest

You can now execute the following command to pull the hello word image from Docker Hub.

AZDIGI Tutorial
docker-compose up
    

And here is the result after running the command:

CleanShot 2022 05 14 at 17.16.47

So the hello-world image is taken from Docker Hub and docker-compose creates an attached container and runs the program.

  • To view all existing containers, use the command:
AZDIGI Tutorial
docker ps -a
    
CleanShot 2022 05 14 at 17.19.42

Thus, in this article, AZDIGI showed you how to install and use Docker compose on Ubuntu 22.04 very simply. Hopefully, this article will be helpful to you. Wishing you success!

You can refer to other instructions at the link below:

If you need support, you can contact support in the ways below:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign