How to Install Docker on UBUNTU Server
Posted by Mir Sayeed Hassan on November 1st, 2023
How to Install Docker on UBUNTU Server
Check the IP address to assign into the resolv.conf file
nameserver 178.22.***.***
ubuntu@mir-docker-test:~$ sudo cat /etc/resolv.conf nameserver 178.22.***.***--- this file is added nameserver 127.0.0.53 options edns0 search openstacklocal
This command will remove if any Docker is install before in this server.
ubuntu@mir-docker-test:~$ sudo apt-get remove docker docker-engine docker.io containerd runc Reading package lists... Done Building dependency tree Reading state information... Done Package 'docker-engine' is not installed, so not removed Package 'docker' is not installed, so not removed Package 'containerd' is not installed, so not removed Package 'docker.io' is not installed, so not removed Package 'runc' is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Update the repository of this server.
ubuntu@mir-docker-test:~$ sudo apt-get update Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB] Get:2 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [1399 kB] Get:3 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [166 kB] Get:4 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1079 kB] Get:5 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [12.9 kB] Hit:6 http://nova.clouds.archive.ubuntu.com/ubuntu bionic InRelease Get:7 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB] Get:8 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB] Get:9 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [1726 kB] Get:10 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [184 kB] Get:11 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1683 kB] Get:12 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [31.9 kB] Get:13 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [10.0 kB] Get:14 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [10.3 kB] Fetched 6553 kB in 5s (1276 kB/s) Reading package lists... Done
ubuntu@mir-docker-test:~$ sudo apt-get install \ > apt-transport-https \ > ca-certificates \ > curl \ > gnupg-agent \ > software-properties-common Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: dirmngr gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm gpgv libcurl4 python3-software-properties Suggested packages: dbus-user-session pinentry-gnome3 tor parcimonie xloadimage scdaemon The following NEW packages will be installed: apt-transport-https gnupg-agent The following packages will be upgraded: ca-certificates curl dirmngr gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm gpgv libcurl4 python3-software-properties software-properties-common 16 upgraded, 2 newly installed, 0 to remove and 106 not upgraded. Need to get 2716 kB of archives. After this operation, 224 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpg-wks-client amd64 2.2.4-1ubuntu1.3 [91.8 kB] Get:2 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-updates/main amd64 dirmngr amd64 2.2.4-1ubuntu1.3 [316 kB] Continue................ 0 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d... done.
Download the ubuntu from docker site
ubuntu@mir-docker-test:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - OK
Repository will add into the local repository
ubuntu@mir-docker-test:~$ sudo add-apt-repository \ > "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ > $(lsb_release -cs) \ > stable" Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease Get:2 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB] Get:3 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [13.0 kB] Hit:4 http://nova.clouds.archive.ubuntu.com/ubuntu bionic InRelease Hit:5 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-updates InRelease Hit:6 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-backports InRelease Fetched 77.4 kB in 4s (18.0 kB/s) Reading package lists... Done
Update the repository
ubuntu@mir-docker-test:~$ sudo apt-get update Hit:1 http://nova.clouds.archive.ubuntu.com/ubuntu bionic InRelease Hit:2 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-updates InRelease Hit:3 http://security.ubuntu.com/ubuntu bionic-security InRelease Hit:4 http://nova.clouds.archive.ubuntu.com/ubuntu bionic-backports InRelease Hit:5 https://download.docker.com/linux/ubuntu bionic InRelease Reading package lists... Done
Start the Installation of docker. ubuntu@mir-docker-test:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io Reading package lists... Done Building dependency tree Reading state information... Done Recommended packages: aufs-tools cgroupfs-mount | cgroup-lite pigz libltdl7 The following NEW packages will be installed: containerd.io docker-ce docker-ce-cli 0 upgraded, 3 newly installed, 0 to remove and 106 not upgraded. Need to get 91.1 MB of archives. After this operation, 409 MB of additional disk space will be used. Get:1 https://download.docker.com/linux/ubuntu bionic/stable amd64 containerd.io amd64 1.3.7-1 [24.4 MB] Get:2 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce-cli amd64 5:19.03.13~3-0~ubuntu-bionic [44.2 MB] Get:3 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce amd64 5:19.03.13~3-0~ubuntu-bionic [22.5 MB] Fetched 91.1 MB in 4s (23.8 MB/s) Selecting previously unselected package containerd.io. (Reading database ... 40106 files and directories currently installed.) Preparing to unpack .../containerd.io_1.3.7-1_amd64.deb ... Unpacking containerd.io (1.3.7-1) ... Selecting previously unselected package docker-ce-cli. Preparing to unpack .../docker-ce-cli_5%3a19.03.13~3-0~ubuntu-bionic_amd64.deb ... Unpacking docker-ce-cli (5:19.03.13~3-0~ubuntu-bionic) ... Selecting previously unselected package docker-ce. Preparing to unpack .../docker-ce_5%3a19.03.13~3-0~ubuntu-bionic_amd64.deb ... Unpacking docker-ce (5:19.03.13~3-0~ubuntu-bionic) ... Setting up containerd.io (1.3.7-1) ... Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service. Setting up docker-ce-cli (5:19.03.13~3-0~ubuntu-bionic) ... Setting up docker-ce (5:19.03.13~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 systemd (237-3ubuntu10.41) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Processing triggers for ureadahead (0.100.0-21) ...
We does not have permission
ubuntu@mir-docker-test:~$ docker ps Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied
Add the user into the user to access the above user
ubuntu@mir-docker-test:~$ sudo usermod -aG docker ubuntu
This will check any docker container is up & running
ubuntu@mir-docker-test:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1c08a7a0d0e4 ubuntu "/bin/bash" 3 minutes ago Up 5 seconds docker-ce
To stop a running container, use docker stop, followed by the container ID or name.
ubuntu@mir-docker-test:~$ docker stop docker-ce
In case if you want to remove the container use the below command.
ubuntu@mir-docker-test:~$ docker rm docker-ce