Docker Installation on Ubuntu Linux Troubleshoot.

Docker Installation on Ubuntu Linux Troubleshoot.

# Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I recently installed docker on Ubuntu following the installation instructions from the official docker documentation, https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository.

The steps according to the documentation are;

  1. Set up Docker's Apt repository.

  2. Install the Docker packages.

  3. Verify that the Docker Engine installation is successful by running the hello-world image.

On running step 3 which entails running the following command, sudo docker run hello-worldor any docker command, I kept getting the error below,

sudo docker run hello-world docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

To solve this issue;

1. Check if the Docker Group Exists:

First, check if the docker group exists on your system by running the following command:

grep 'docker:' /etc/group

If the group doesn’t exist, create one using the following command:

sudo groupadd docker

2. To determine the user/username on Ubuntu, run the following command:

whoami

3. Add Your User to the docker Group:

sudo usermod -aG docker <your-username>

Replace <your-username> with your actual username:

sudo usermod -aG docker john

4. Log Out and Log Back In:

For the group changes to take effect, you need to log out of your current session and then log back in. Alternatively, you can restart your system.

  1. Verify Group Membership:

After logging back in, you can verify that your user is now a member of the docker group by running:

groups

You should see docker listed among the groups for your user.

6. Run the command below to enable docker to run on boot:

sudo systemctl enable docker

  1. Check for Conflicting Configuration:

Ensure that there are no conflicting Docker configurations or environment variables that might be causing issues. Check your shell profile files (e.g., .bashrc, .zshrc, etc.) for any Docker-related environment variable settings and remove them if necessary.

Open your ~/.bashrc file using a text editor, we’ll use Nano as a text editor because it’s the best option.

nano ~/.bashrc

  1. Add the following lines to the end of the ~/.bashrc file:

export DOCKER_HOST="tcp://127.0.0.1:2375"

alias docker="sudo docker"

  1. Save the file and exit the text editor.

You can usually do this for nano by pressing Ctrl + O to save and Ctrl + X to exit.

10. To apply the changes to your current terminal session, source the ~/.bashrc file:

source ~/.bashrc source ~/.bashrc

Did you find this article valuable?

Support Stanley Waweru by becoming a sponsor. Any amount is appreciated!