Install docker engine on Ubuntu

Views: 11
0 0
Read Time:3 Minute, 1 Second

Docker has revolutionized the way software is packaged, shipped, and deployed, offering unparalleled flexibility and efficiency for developers and system administrators alike. For Ubuntu users looking to harness the power of containerization, installing Docker Engine is the crucial first step. Whether you’re a seasoned sysadmin or a newcomer to the world of containers, this guide will walk you through the step-by-step process of installing Docker Engine on Ubuntu. Join us as we unlock the potential of Docker and streamline your development and deployment workflows on Ubuntu.

Let’s start from here (https://docs.docker.com/engine/install/) that will drive you here (https://docs.docker.com/engine/install/ubuntu/)

Let’s follow the steps then:

sudo apt-get remove docker docker-engine docker.io containerd runc

Now let’s setup the repository

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Add the GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Then setup the stable repository with $(lsb_release -cs) stable

echo \
  "deb [arch=amd64 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

And then….install

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

The second command gave me an error (related to my ubuntu version, the same will happen with Linux Mint)

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
E: Unable to locate package docker-ce-cli
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io'
E: Couldn't find any package by regex 'containerd.io'

To overcome this issue we have to run this command instead

sudo apt-get install docker.io

The last command will install the docker engine and we can verify by typing

$ docker -v
Docker version 20.10.2, build 20.10.2-0ubuntu1~20.04.2

That’s great so far, however there is one last thing we should do because is not working as expected. In fact if we want to list the docker containers, or docker images we will get this error

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.24/containers/json: dial unix /var/run/docker.sock: connect: permission denied

docker images: 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.24/images/json: dial unix /var/run/docker.sock: connect: permission denied

This will not happen if we run the command as sudo

$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

What we need to do for fixing this problem is to:

# register your user to the docker group
sudo usermod -aG docker ${USER}
# logout and login again

And now everything is magically working as expected (there is no magic in computer science…only spells)

docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
$ docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

Of course this is now empty, but in one the next articles we will see how to populate these.

Hope you enjoyed and was helpful if so, share and help us grow!

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
Previous post Building Your Own Docker Container Step-by-Step Guide
Next post How to install MySQL on your Linux System
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x