Hướng dẫn cài đặt docker lên Ubuntu 22.04

Để thực hiện cài đặt Docker cho VPS ubuntu 22.04 bạn cần phải thực hiện các thao tác sau đây :

Bước 1 : Đăng nhập SSH vào VPS với thông tin HostVN đã gửi qua email.

Bước 2 : Cài đặt docker với câu lệnh sau

apt install docker.io

Bước 3 : Khởi động và bật docker 

systemctl enable --now docker

Bước 4 : Xem tình trạng của docker

systemctl status docker

Kết quả trả về như sau 

root@phuong:~# systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2024-11-01 09:03:22 +07; 3min 21s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 40470 (dockerd)
      Tasks: 9
     Memory: 24.6M
        CPU: 487ms
     CGroup: /system.slice/docker.service
             └─40470 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Vậy là bạn đã cài xong docker rồi giờ chúng ta hãy test việc sử dụng docker:

Tạo nhóm docker:

sudo groupadd docker

Thêm user vào nhóm docker :

sudo usermod -aG docker $USER

Nhớ thay $USER bằng tên user của bạn nhé

Kiểm tra phiên bản docker:

docker --version

Kết quả trả về như sau  

root@phuong:~# docker --version
Docker version 24.0.7, build 24.0.7-0ubuntu2~22.04.1

Thử sử dụng docker với hello-world container:

docker run hello-world

Kết quả trả về như sau:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/



Article ID: 1094
Cập nhật gần nhất: 01 Th11, 2024
Lần sửa đổi: 1
VPS (Máy chủ ảo) -> VPS Linux -> Hướng dẫn cài đặt docker lên Ubuntu 22.04
https://kb.hostvn.net/hung-dn-cai-dat-docker-len-ubuntu-2204_1094.html