In this Docker Tutorials, we will explain the steps to install Docker on Ubuntu Bionic 18.04 (LTS).
OS requirements
To install Docker Engine – Community, we have taken 64-bit version Ubuntu versions 18.04
- Eoan 19.10
- Bionic 18.04 (LTS)
- Xenial 16.04 (LTS)
[ads1]
Command to uninstall old Docker versions from Ubuntu
$ sudo apt-get remove docker* docker-engine docker.io containerd runc
[box type=”info” align=”” class=”” width=””]You can ignore if you get output “none of these packages are installed”, which says that the package is not installed.[/box]
The Docker Engine – Community package is now called docker-ce
Steps to Install Docker on Ubuntu
There are different ways you can install Docker on Ubuntu:
- Setup Docker Repository – This method is very useful for installing and upgrading the Docker version. (Recommend)
- Download DEB package and install it manually. This method is used when you are not allowed to provide internet access on your Ubuntu server)
- Automated Script to install Docker (Not recommended for Production)
[divider style=”normal” top=”20″ bottom=”20″]
Steps to Install Docker on Ubuntu using Docker Repository on Ubuntu:
[ads3]
Step 1. Update the apt package index:
$ sudo apt-get update
Sample Output:
root@docker-setup:/home/ubuntu# sudo apt-get update Hit:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease Hit:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease Hit:4 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease Reading package lists... Done root@docker-setup:/home/ubuntu#
Step 2. Install packages to use a repository over HTTPS for apt:
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
[ads2]
Sample Output:
root@docker-setup:/home/ubuntu# sudo apt-get install \ > apt-transport-https \ > ca-certificates \ > curl \ > gnupg-agent \ > Reading package lists... Done Building dependency tree Reading state information... Done ca-certificates is already the newest version (20180409). ca-certificates set to manually installed. curl is already the newest version (7.58.0-2ubuntu3.8). curl set to manually installed. The following NEW packages will be installed: apt-transport-https gnupg-agent 0 upgraded, 2 newly installed, 0 to remove and 57 not upgraded. Need to get 6572 B of archives. After this operation, 196 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 apt-transport-https all 1.6.12 [1692 B] Get:2 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 gnupg-agent all 2.2.4-1ubuntu1.2 [4880 B] Fetched 6572 B in 0s (16.7 kB/s) Selecting previously unselected package apt-transport-https. (Reading database ... 56554 files and directories currently installed.) Preparing to unpack .../apt-transport-https_1.6.12_all.deb ... Unpacking apt-transport-https (1.6.12) ... Selecting previously unselected package gnupg-agent. Preparing to unpack .../gnupg-agent_2.2.4-1ubuntu1.2_all.deb ... Unpacking gnupg-agent (2.2.4-1ubuntu1.2) ... Setting up apt-transport-https (1.6.12) ... Setting up gnupg-agent (2.2.4-1ubuntu1.2) ... root@docker-setup:/home/ubuntu#
Step 3. Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
Sample Output:
root@docker-setup:/home/ubuntu# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - OK root@docker-setup:/home/ubuntu#
[ads4]
Step 4. Docker repository to APT sources
$ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
Sample Output:
root@docker-setup:/home/ubuntu# sudo add-apt-repository \ > "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ > $(lsb_release -cs) \ > stable" Get:1 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB] Get:2 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [10.7 kB] Get:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease [242 kB] Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease Get:5 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB] Get:6 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB] Fetched 480 kB in 2s (291 kB/s) Reading package lists... Done root@docker-setup:/home/ubuntu#
Step 5. Update the apt package index.
$ sudo apt-get update
Sample output:
root@docker-setup:/home/ubuntu# sudo apt-get update Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease Get:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease [242 kB] Hit:4 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease Hit:5 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease Fetched 242 kB in 1s (182 kB/s) Reading package lists... Done root@docker-setup:/home/ubuntu#
[ads2]
Step 6. Ubuntu Command to install Docker and containerd
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Sample Output:
root@docker-setup:/home/ubuntu# sudo apt-get install docker-ce docker-ce-cli containerd.io Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: aufs-tools cgroupfs-mount libltdl7 pigz The following NEW packages will be installed: aufs-tools cgroupfs-mount containerd.io docker-ce docker-ce-cli libltdl7 pigz 0 upgraded, 7 newly installed, 0 to remove and 57 not upgraded. Need to get 85.8 MB of archives. After this operation, 385 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 https://download.docker.com/linux/ubuntu bionic/stable amd64 containerd.io amd64 1.2.13-1 [20.1 MB] Get:2 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce-cli amd64 5:19.03.7~3-0~ubuntu-bionic [42.5 MB] Get:3 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic/universe amd64 pigz amd64 2.4-1 [57.4 kB] Get:4 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce amd64 5:19.03.7~3-0~ubuntu-bionic [22.9 MB] Get:5 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic/universe amd64 aufs-tools amd64 1:4.9+20170918-1ubuntu1 [104 kB] Get:6 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic/universe amd64 cgroupfs-mount all 1.4 [6320 B] Get:7 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 libltdl7 amd64 2.4.6-2 [38.8 kB] Fetched 85.8 MB in 4s (22.8 MB/s) Selecting previously unselected package pigz. (Reading database ... 56562 files and directories currently installed.) Preparing to unpack .../0-pigz_2.4-1_amd64.deb ... Unpacking pigz (2.4-1) ... Selecting previously unselected package aufs-tools. Preparing to unpack .../1-aufs-tools_1%3a4.9+20170918-1ubuntu1_amd64.deb ... Unpacking aufs-tools (1:4.9+20170918-1ubuntu1) ... Selecting previously unselected package cgroupfs-mount. Preparing to unpack .../2-cgroupfs-mount_1.4_all.deb ... Unpacking cgroupfs-mount (1.4) ... Selecting previously unselected package containerd.io. Preparing to unpack .../3-containerd.io_1.2.13-1_amd64.deb ... Unpacking containerd.io (1.2.13-1) ... Selecting previously unselected package docker-ce-cli. Preparing to unpack .../4-docker-ce-cli_5%3a19.03.7~3-0~ubuntu-bionic_amd64.deb ... Unpacking docker-ce-cli (5:19.03.7~3-0~ubuntu-bionic) ... Selecting previously unselected package docker-ce. Preparing to unpack .../5-docker-ce_5%3a19.03.7~3-0~ubuntu-bionic_amd64.deb ... Unpacking docker-ce (5:19.03.7~3-0~ubuntu-bionic) ... Selecting previously unselected package libltdl7:amd64. Preparing to unpack .../6-libltdl7_2.4.6-2_amd64.deb ... Unpacking libltdl7:amd64 (2.4.6-2) ... Setting up aufs-tools (1:4.9+20170918-1ubuntu1) ... Setting up containerd.io (1.2.13-1) ... Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service. Setting up cgroupfs-mount (1.4) ... Setting up libltdl7:amd64 (2.4.6-2) ... Setting up docker-ce-cli (5:19.03.7~3-0~ubuntu-bionic) ... Setting up pigz (2.4-1) ... Setting up docker-ce (5:19.03.7~3-0~ubuntu-bionic) ... 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 libc-bin (2.27-3ubuntu1) ... Processing triggers for systemd (237-3ubuntu10.33) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Processing triggers for ureadahead (0.100.0-21) ... root@docker-setup:/home/ubuntu#
Step 7: Verify that Docker Engine running correctly with hello-world image
$ sudo docker run hello-world
Sample output:
root@docker-setup:/home/ubuntu# sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:fc6a51919cfeb2e6763f62b6d9e8815acbf7cd2e476ea353743570610737b752 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly.
Step 8: Command to check Docker version:
$ docker -v
root@docker-setup:/home/ubuntu# docker -v Docker version 19.03.7, build 7141c199a2 root@docker-setup:/home/ubuntu#
[divider style=”solid” top=”20″ bottom=”20″]
Steps to download Docker DEB package and install manually
This is the another method or steps to Install Docker on Ubuntu.
[ads1]
Step 1: Download DEB package for Ubuntu
Choose your Ubuntu version and download DEB package from link
Command to check Ubuntu release:
$ lsb_release -cs
Sample Output:
root@docker-setup:/home/ubuntu# lsb_release -cs bionic root@docker-setup:/home/ubuntu#
Download on your ubuntu server using curl command or you can download from the browser and copy on the Ubuntu server.
Step 2: Command to install Docker DEB package on Ubuntu
$ sudo dpkg -i /path/to/package.deb
Docker daemon starts automatically.
Step 3: Verify that Docker Engine running properly with the hello-world image
$ sudo docker run hello-world
[divider style=”solid” top=”20″ bottom=”20″]
Steps to install docker using the automation script
Follow below steps to Install Docker on Ubuntu:
[box type=”warning” align=”” class=”” width=””]This step is not recommended for Production Setup[/box]
[button color=”orange” size=”small” link=”https://github.com/docker/docker-install/blob/master/install.sh” icon=”” target=”true” nofollow=”true”]Docker Install Script[/button]
Docker install Script
$ curl -fsSL https://get.docker.com -o get-docker.sh $ sudo sh get-docker.sh
[ads3]
Steps to Remove or Uninstall Docker from Ubuntu
Step 1: Command to remove the Docker community package
$ sudo apt-get purge docker-ce docker*
Step 2: Remove data/files from a host like containers, Images, volumes. these are not removed automatically
$ sudo rm -rf /var/lib/docker
This is the end of Docker Tutorials, where we have explained the steps to install Docker on Ubuntu Bionic 18.04 (LTS).
[highlight color=”green”]Read other articles[/highlight]
Steps to Install Python in Ubuntu