12/28/2021

Using Docker On Ubuntu

83
  1. Using Docker On Ubuntu Linux
  2. Using Docker On Ubuntu Windows 10

Recently, I installed Docker on Ubuntu. It was super easy. But when I tried to run a docker command, it threw this error at me:

Install Docker Engine, changing the path below to the path where you downloaded the Docker package. $ sudo dpkg -i /path/to/package.deb. The Docker daemon starts automatically. Verify that Docker Engine is installed correctly by running the hello-world image. $ sudo docker run hello-world. Use the command: sudo apt-get remove docker docker-engine docker.io Step 3: Install Docker on Ubuntu 18.04. To install Docker on Ubuntu, in the terminal window enter the command: sudo apt install docker.io Step 4: Start and Automate Docker. The Docker service needs to be setup to run at startup. To do so, type in each command followed by enter.

It’s not that I am trying to run something special. It happens for basic docker command like ps as well.

Strange, isn’t it? Let me show you how to get past this annoying error.

Fixing ‘Got permission denied while trying to connect to the Docker daemon socket’ error with Docker in Ubuntu

There are two ways to deal with it.

Fix 1: Run all the docker commands with sudo

If you have sudo access on your system, you may run each docker command with sudo and you won’t see this ‘Got permission denied while trying to connect to the Docker daemon socket’ anymore.

But running each and every docker command with sudo is super inconvenient. You miss adding sudo to the beginning and you’ll get ‘permission denied’ error again.

Fix 2: Running docker commands without sudo

To run the docker commands without sudo, you can add your user account (or the account you are trying to fix this problem for) to the docker group.

First, create the docker group using groupadd command. The group may already exist but running the group creation command won’t hurt.

Now that you have the docker group, add your user to this group with the usermod command. I am assuming that you are trying to do it for your own user account and in that case, you can use the $USER variable.

Verify that your user has been added to docker group by listing the users of the group. You probably have to log out and log in back again.

If you check your groups and docker groups is not listed even after logging out, you may have to restart Ubuntu. To avoid that, you can use the newgrp command liks this:

Now if you try running the docker commands without sudo, it should work just fine.

Further troubleshooting

In some cases, you may need to add additional permissions to some files specially if you have run the docker commands with sudo in the past.

You may try changing the group ownership of the /var/run/docker.sock file.

You may also try changing the group ownership of the ~/.docker directory.

And then try running docker with sudo. It should be fine.

I hope this little tutorial helped you to fix the annoying “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.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied” error with Docker in Ubuntu.

Did it fix the problem for you? If yes, I welcome a quick comment of thanks from you. If not, I’ll be happy to help you fix this problem further.

This tutorial explains, how to install docker on Ubuntu.

Docker

Docker is a platform that combines applications and its dependencies in the form of packages called a container. We can run multiple containers on a single Operating System. Containers are not Virtual Machines. Virtual Machines requires Operating System to run applications, but containers do not. As containers don’t need an Operating System, it takes very little time to start and hence it is very faster than Virtual Machines.

Read About: How to Install Docker on Windows

&& How to install Ansible on Ubuntu

Install Docker on Ubuntu

Step 1- Update your Ubuntu Linux Box.

Install docker on ubuntu 18.04

$ sudo apt-get update -y

Step 2 – Download and run a get-docker.sh script to install docker.

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

or you can Download and run Test Script.

Using

Download and run testing version, download and install test-docker.sh script using the following commands.

$ curl -fsSL https://get.docker.com -o test-docker.sh
$ sudo sh test-docker.sh

Step 3- Add a user to the Docker group.

If you would like to use Docker with a non-root user, using the following command.

Add a new user docker-user and set a password

Using Docker On Ubuntu Linux

$ sudo useradd docker-user

$ sudo passwd docker-user

Using docker on ubuntu download

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Add docker-user to Docker group

$ sudo usermod -aG docker docker-user

Step 4 – Check Docker Version

Check Docker Version using the following command

$ docker – -version
Docker version 19.03.8, build afacb8b7f0

Uninstall Docker on Ubuntu

Use the following command to uninstall docker completely, including Docker Engine, CLI and Containerd Package

$ sudo apt-get purge docker-ce docker-ce-cli containerd.io -y

Ubuntu

Also delete all Docker Images, Containers, and Volumes that not automatically remove.

$ sudo rm -rf /var/lib/docker

Note: If you install docker using the script, you should update the docker using the package manager only. Don’t re-run docker script, as it can cause issues if it attempts to re-add repositories.

I hope you enjoyed this tutorial and learned about “How to install Docker on Ubuntu using Script”. If you think this is really helpful, please do share this article with others as well. Please also share your valuable feedback, comment, or any query in the comment box. I will really happy to resolve your all queries any.

Thank You

Using Docker On Ubuntu Windows 10

If you think we helped you or just want to support us, please consider these:-

Connect to us: FacebookTwitter

  • Most Viewed News

    • Catalina Mac Os Update
    • Nordvpn Free Download Mac
    • Pastebot
    • Torrent Imovie