Docker is an open platform for developing, build, shipping, running the applications very quickly. Docker able to separate your application from your infrastructure. The docker used to build the softwares in a docker image and running in containers.
We are able to easily manage our infrastructure in the same ways you manage your applications. This post will helps you how to install a Docker engine or Docker daemon in your Ubuntu 20.04 machine.
Installation steps:
Just open the Terminal window and Remove if any Docker containers are running in the machine, the command is,
$ sudo apt-get remove docker docker-engine docker.io
Check if the system is up-to-date using the command below,
$ apt-get update
Install a Docker in your system and if you may received the errors, just install prerequisite packages, GPG Key and add the Docker repository,
$ sudo apt install docker-ce
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'docker-ce' has no installation candidate
Then, install some of the prerequisite packages which let apt use packages using the command below,
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add the GPG key for the official Docker repository to your system,
$curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add the Docker repository to APT sources using the command below,
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
Once you have executed the commands above, then we will install the docker engine in your machine,
sudo apt install docker-ce
If you would like to give grant prevellege the users access the docker without sudo add your username to the docker group
$ sudo usermod -aG docker ${USER}
I hope, the docker is installed in your without any issue, then start the docker engine using the command,
$ sudo service docker start
If you want to check the docker daemon running status,
$ sudo service docker status
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-07-20 04:02:11 UTC; 10 minutes ago
Docs: https://docs.docker.com
Main PID: 1119 (dockerd)
Tasks: 38
CGroup: /system.slice/docker.service
├─1119 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Run a sample container:
Lets go to run a sample docker container with NGINX webserver,
$ docker run -itd --name thelinuxfaq-nginx nginx:latest
If the docker nginx image is already not available in your local machine, it would be downloaded automatically and run the nginx image in a contianer,
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
461246efe0a7: Already exists
060bfa6be22e: Pull complete
b34d5ba6fa9e: Pull complete
8128ac56c745: Pull complete
44d36245a8c9: Pull complete
ebcc2cc821e6: Pull complete
Digest: sha256:1761fb5661e4d77e107427d8012ad3a5955007d997e0f4a3d41acc9ff20467c7
Status: Downloaded newer image for nginx:latest
89257ff4c27c0d263e00694ffed71e7cfb9cfbbf7e0f3ef633e4cd7d7c449780
List out the running docker container,
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89257ff4c27c nginx:latest "/docker-entrypoint.…" 5 seconds ago Up 4 seconds 80/tcp thelinuxfaq-nginx
Oh sorry, I forgot to add or expose a container's port(s) to the host. -p option is helps you,
$ docker run -itd --name thelinuxfaq-nginx -p 8090:80 nginx:latest
f6de23fea6c819c1ef11fa717378aabb53d7f24e486ba2f65950e2037840e0f5
Now, you can see the nginx container is running with the port expose 8090,
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f6de23fea6c8 nginx:latest "/docker-entrypoint.…" 6 seconds ago Up 5 seconds 0.0.0.0:8090->80/tcp thelinuxfaq-nginx
Now, open your browser and use the URL: http://localhost:8090.
that's it.
Comments (0)