Docker has revolutionized the way developers create, deploy, and manage applications by enabling lightweight containerization technology, which allows for easy management and isolation of applications and their dependencies. In this tutorial, we will guide you through the process of installing Docker on Ubuntu 22.04, the latest long-term support (LTS) release of this popular Linux distribution. We will begin by discussing the benefits of using Docker and why it is essential for modern development workflows. Next, we will cover the necessary system requirements and prerequisites for a successful installation.
Prerequisites
Before we begin, ensure that you have:
- A system running Ubuntu 22.04.
- A user account with sudo privileges.
Step 1: Update your system
Before installing any new software, it’s always a good idea to update your system packages. Open the terminal and run the following commands:
sudo apt update sudo apt upgrade
Step 2: Install required dependencies
To install Docker on Ubuntu, we need to install some necessary dependencies first. Run the following command to install them
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Hasil output sebagai berikut :
root@masadmin:~# sudo apt install apt-transport-https ca-certificates curl software-properties-common Reading package lists... Done Building dependency tree... Done Reading state information... Done ca-certificates is already the newest version (20230311ubuntu0.22.04.1). ca-certificates set to manually installed. curl is already the newest version (7.81.0-1ubuntu1.10). curl set to manually installed. software-properties-common is already the newest version (0.99.22.7). software-properties-common set to manually installed. The following packages were automatically installed and are no longer required: libflashrom1 libftdi1-2 Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: apt-transport-https 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 1,510 B of archives. After this operation, 169 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://id.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 apt-transport-https all 2.4.9 [1,510 B] Fetched 1,510 B in 1s (3,014 B/s) Selecting previously unselected package apt-transport-https. (Reading database ... 109509 files and directories currently installed.) Preparing to unpack .../apt-transport-https_2.4.9_all.deb ... Unpacking apt-transport-https (2.4.9) ... Setting up apt-transport-https (2.4.9) ... Scanning processes... Scanning candidates... Scanning linux images... Restarting services... Service restarts being deferred: /etc/needrestart/restart.d/dbus.service systemctl restart networkd-dispatcher.service systemctl restart systemd-logind.service systemctl restart unattended-upgrades.service systemctl restart [email protected] No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host. root@masadmin:~#
Step 3: Add Docker repository
Next, we will add the official Docker repository to our system. First, add the GPG key for the Docker repository:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Hasil output :
root@masadmin:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg root@masadmin:~#
Then, add the Docker repository to your system with the following command:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Hasil output :
root@masadmin:~# echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null root@masadmin:~#
Step 4: Install Docker
Now that we have added the Docker repository, update your package index:
sudo apt update
Then, install Docker with the following command:
sudo apt install docker-ce docker-ce-cli containerd.io
Hasil output sebagai berikut :
root@masadmin:~# sudo apt install docker-ce docker-ce-cli containerd.io Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: libflashrom1 libftdi1-2 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: docker-buildx-plugin docker-ce-rootless-extras docker-compose-plugin libltdl7 libslirp0 pigz slirp4netns Suggested packages: aufs-tools cgroupfs-mount | cgroup-lite The following NEW packages will be installed: containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin libltdl7 libslirp0 pigz slirp4netns 0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded. Need to get 114 MB of archives. After this operation, 414 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 pigz amd64 2.6-1 [63.6 kB] Get:2 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 libltdl7 amd64 2.4.6-15build2 [39.6 kB] Get:3 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 libslirp0 amd64 4.6.1-1build1 [61.5 kB] Get:4 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 slirp4netns amd64 1.0.1-2 [28.2 kB] Get:5 https://download.docker.com/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.6.21-1 [28.3 MB] Get:6 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-buildx-plugin amd64 0.11.1-1~ubuntu.22.04~jammy [28.2 MB] Get:7 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:24.0.4-1~ubuntu.22.04~jammy [13.3 MB] Get:8 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:24.0.4-1~ubuntu.22.04~jammy [22.9 MB] Get:9 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:24.0.4-1~ubuntu.22.04~jammy [9,033 kB] Get:10 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-compose-plugin amd64 2.19.1-1~ubuntu.22.04~jammy [11.9 MB] Fetched 114 MB in 56s (2,021 kB/s) Selecting previously unselected package pigz. (Reading database ... 109513 files and directories currently installed.) Preparing to unpack .../0-pigz_2.6-1_amd64.deb ... Unpacking pigz (2.6-1) ... Selecting previously unselected package containerd.io. Preparing to unpack .../1-containerd.io_1.6.21-1_amd64.deb ... Unpacking containerd.io (1.6.21-1) ... Selecting previously unselected package docker-buildx-plugin. Preparing to unpack .../2-docker-buildx-plugin_0.11.1-1~ubuntu.22.04~jammy_amd64.deb ... Unpacking docker-buildx-plugin (0.11.1-1~ubuntu.22.04~jammy) ... Selecting previously unselected package docker-ce-cli. Preparing to unpack .../3-docker-ce-cli_5%3a24.0.4-1~ubuntu.22.04~jammy_amd64.deb ... Unpacking docker-ce-cli (5:24.0.4-1~ubuntu.22.04~jammy) ... Selecting previously unselected package docker-ce. Preparing to unpack .../4-docker-ce_5%3a24.0.4-1~ubuntu.22.04~jammy_amd64.deb ... Unpacking docker-ce (5:24.0.4-1~ubuntu.22.04~jammy) ... Selecting previously unselected package docker-ce-rootless-extras. Preparing to unpack .../5-docker-ce-rootless-extras_5%3a24.0.4-1~ubuntu.22.04~jammy_amd64.deb ... Unpacking docker-ce-rootless-extras (5:24.0.4-1~ubuntu.22.04~jammy) ... Selecting previously unselected package docker-compose-plugin. Preparing to unpack .../6-docker-compose-plugin_2.19.1-1~ubuntu.22.04~jammy_amd64.deb ... Unpacking docker-compose-plugin (2.19.1-1~ubuntu.22.04~jammy) ... Selecting previously unselected package libltdl7:amd64. Preparing to unpack .../7-libltdl7_2.4.6-15build2_amd64.deb ... Unpacking libltdl7:amd64 (2.4.6-15build2) ... Selecting previously unselected package libslirp0:amd64. Preparing to unpack .../8-libslirp0_4.6.1-1build1_amd64.deb ... Unpacking libslirp0:amd64 (4.6.1-1build1) ... Selecting previously unselected package slirp4netns. Preparing to unpack .../9-slirp4netns_1.0.1-2_amd64.deb ... Unpacking slirp4netns (1.0.1-2) ... Setting up docker-buildx-plugin (0.11.1-1~ubuntu.22.04~jammy) ... Setting up containerd.io (1.6.21-1) ... Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service. Setting up docker-compose-plugin (2.19.1-1~ubuntu.22.04~jammy) ... Setting up libltdl7:amd64 (2.4.6-15build2) ... Setting up docker-ce-cli (5:24.0.4-1~ubuntu.22.04~jammy) ... Setting up libslirp0:amd64 (4.6.1-1build1) ... Setting up pigz (2.6-1) ... Setting up docker-ce-rootless-extras (5:24.0.4-1~ubuntu.22.04~jammy) ... Setting up slirp4netns (1.0.1-2) ... Setting up docker-ce (5:24.0.4-1~ubuntu.22.04~jammy) ... Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service. Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket. Processing triggers for man-db (2.10.2-1) ... Processing triggers for libc-bin (2.35-0ubuntu3.1) ... Scanning processes... Scanning candidates... Scanning linux images... Restarting services... Service restarts being deferred: /etc/needrestart/restart.d/dbus.service systemctl restart networkd-dispatcher.service systemctl restart systemd-logind.service systemctl restart unattended-upgrades.service systemctl restart [email protected] No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host. root@masadmin:~#
Step 5: Verify Docker installation
To verify that Docker has been installed successfully, run the following command:ADVERTISEMENT
sudo docker --version
You should see output similar to this, indicating the installed Docker version:
root@masadmin:~# sudo docker --version Docker version 24.0.4, build 3713ee1 root@masadmin:~#
Step 6: Manage Docker service
Docker should now be installed and running as a background service. To check the status of the Docker service, run:
sudo systemctl status docker
Hasil output :
root@masadmin:~# sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2023-07-08 04:26:23 UTC; 2min 18s ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 49940 (dockerd) Tasks: 16 Memory: 25.7M CPU: 280ms CGroup: /system.slice/docker.service └─49940 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Jul 08 04:26:22 masadmin systemd[1]: Starting Docker Application Container Engine... Jul 08 04:26:22 masadmin dockerd[49940]: time="2023-07-08T04:26:22.995816512Z" level=info msg="Starting up" Jul 08 04:26:22 masadmin dockerd[49940]: time="2023-07-08T04:26:22.996477307Z" level=info msg="detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: /run/systemd/resolve/resolv> Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.069858653Z" level=info msg="Loading containers: start." Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.311366853Z" level=info msg="Loading containers: done." Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.325269029Z" level=info msg="Docker daemon" commit=4ffc614 graphdriver=overlay2 version=24.0.4 Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.325351398Z" level=info msg="Daemon has completed initialization" Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.360014178Z" level=info msg="API listen on /run/docker.sock" Jul 08 04:26:23 masadmin systemd[1]: Started Docker Application Container Engine. root@masadmin:~#
If the Docker service is not running, you can start it with:
sudo systemctl start docker
root@masadmin:~# sudo systemctl start docker root@masadmin:~#
To enable the Docker service to start automatically at boot, run:
sudo systemctl enable docker
Hasil output sebagai berikut :
root@masadmin:~# sudo systemctl enable docker Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable docker root@masadmin:~# root@masadmin:~# sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2023-07-08 04:26:23 UTC; 3min 24s ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 49940 (dockerd) Tasks: 16 Memory: 25.7M CPU: 281ms CGroup: /system.slice/docker.service └─49940 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Jul 08 04:26:22 masadmin systemd[1]: Starting Docker Application Container Engine... Jul 08 04:26:22 masadmin dockerd[49940]: time="2023-07-08T04:26:22.995816512Z" level=info msg="Starting up" Jul 08 04:26:22 masadmin dockerd[49940]: time="2023-07-08T04:26:22.996477307Z" level=info msg="detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: /run/systemd/resolve/resolv> Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.069858653Z" level=info msg="Loading containers: start." Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.311366853Z" level=info msg="Loading containers: done." Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.325269029Z" level=info msg="Docker daemon" commit=4ffc614 graphdriver=overlay2 version=24.0.4 Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.325351398Z" level=info msg="Daemon has completed initialization" Jul 08 04:26:23 masadmin dockerd[49940]: time="2023-07-08T04:26:23.360014178Z" level=info msg="API listen on /run/docker.sock" Jul 08 04:26:23 masadmin systemd[1]: Started Docker Application Container Engine. lines 1-21/21 (END) root@masadmin:~#
Step 7: Running Docker without sudo (optional)
By default, Docker requires sudo privileges to run. If you want to use Docker without typing ‘sudo’ every time, add your user to the ‘docker’ group with the following command:
sudo usermod -aG docker $USER
Untuk menjalankan perintah, harus keluar dulu dari root atau ganti $USER dengan nama user yang di kehendaki
masadmin@masadmin:~$ sudo usermod -aG docker $USER [sudo] password for masadmin: masadmin@masadmin:~$
Pengecekan group
masadmin@masadmin:~$ cat /etc/group root:x:0: ..... ..... (disingkat) docker:x:999:root,masadmin masadmin@masadmin:~$
After running this command, log out and log back in for the changes to take effect.
Conclusion
Congratulations! You have successfully installed Docker on your Ubuntu 22.04 system. You can now start using Docker to create, deploy, and manage your containerized applications. For more information on using Docker and its features, visit the official Docker documentation: https://docs.docker.com/.