Installing Docker on Ubuntu is a straightforward process that allows you to run containers for lightweight, isolated applications. The steps below shows how to install docker on x86_64 bit ubuntu desktop and have independent ubuntu shell inside docker.
[ Note: docker works only with 64 bit Ubuntu, hence if you have 32 bit Ubuntu machine, it will not work ]
If you have any nonworking traces of docker, remove it using below command,
$ sudo apt-get remove docker docker-engine
Type below commands on your Ubuntu terminal,
$ sudo apt-get update
$ sudo apt install docker.io
above command will install docker command, you can check using “which docker” command and you would see it installed as /usr/bin/docker
Next we need to install docker engine “docker-ce” as,
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Add Docker’s official GPG key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-get update
Now, you can verify that docker-ce package is available to install as,
$ sudo apt search docker-ce
Sorting... Done
Full Text Search... Done
docker-ce/bionic 5:19.03.13~3-0~ubuntu-bionic amd64
Docker: the open-source application container engine
docker-ce-cli/bionic 5:19.03.13~3-0~ubuntu-bionic amd64
Docker CLI: the open-source application container engine
Now, lets check if there is any docker image currently running, which can be checked as,
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
As, you can see above everything is empty, means no image is currently installed..
Now, install the package as,
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
above command will install docker engine and start the service which can be verified as,
$ ps -ax | grep docker
2188 ? Ssl 0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Verify that Docker is installed correctly by running the hello-world image.
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
Status: Downloaded newer image for hello-world:latest
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/
as you see, it pulled the “hello-world” docker image and installed and run this to show the message “Hello from Docker !” which shows you have successfully installed docker on your ubuntu machine.
You can see the “hello-world” docker image installed as,
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 9 months ago 13.3kB
====================
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
The Docker daemon starts automatically. You can verify it as,
ps -ax | grep docker
24946 ? Ssl 0:11 /usr/bin/dockerd –raw-logs
24958 ? Ssl 0:01 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock –metrics-interval=0 –start-timeout 2m –state-dir /var/run/docker/libcontainerd/containerd –shim docker-containerd-shim –runtime docker-runc
Verify that Docker is installed correctly by running the hello-world image.
sudo docker run hello-world
Now to install new ubuntu image, and going to shell, type below command,
sudo docker run -it ubuntu bash
This will take you to new shell, where you can work as needed, and exit using below command,
root@4feb8fa6f496:/# exit
You can check which images has been installed as,
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 6a2f32de169d 35 hours ago 117 MB hello-world latest 48b5124b2768 3 months ago 1.84 kB
$ sudo docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3b4ceb96c87b ubuntu "/bin/bash" About a minute ago Exited (0) About a minute ago peaceful_euler
Start docker container,
sudo docker container start 3b4ceb96c87b 3b4ceb96c87b
This will start docker with basic Ubuntu.