LiJung
LiJung

Reputation: 7959

Docker can't connect to docker daemon

After I update my Docker version to 0.8.0, I get an error message while entering sudo docker version:

Client version: 0.8.0
Go version (client): go1.2
Git commit (client): cc3a8c8
2014/02/19 12:54:16 Can't connect to docker daemon. Is 'docker -d' running on this host?

And I've followed the instructions and entered command sudo docker -d, and I got this:

[/var/lib/docker|2462000b] +job initserver()
[/var/lib/docker|2462000b.initserver()] Creating server
open /var/lib/docker/aufs/layers/cf2414da53f9bcfaa48bc3d58360d7f1cfd3784e4fe51fbef95197709dfc285d: no such file or directory[/var/lib/docker|2462000b] -job initserver() = ERR (1)
2014/02/19 12:55:57 initserver: open /var/lib/docker/aufs/layers/cf2414da53f9bcfaa48bc3d58360d7f1cfd3784e4fe51fbef95197709dfc285d: no such file or directory

How do I solve the problem?

Upvotes: 639

Views: 1116326

Answers (30)

umer sheraz
umer sheraz

Reputation: 21

Just start the docker application

On Mac -> open terminal & type docker

there should be docker icon on top of your menu bar

Upvotes: 0

Momen
Momen

Reputation: 45

Even though, there are plenty of solutions up here. But my case was different a bit.

In my case docker ps was giving this error. But sudo docker ps worked

Check if sudo docker ps works and docker ps doesn't, then try the following:

Check Docker environment variables:

env | grep DOCKER

If nothing is returned, set the DOCKER_HOST variable:

export DOCKER_HOST=unix:///var/run/docker.sock

To make the change permanent, add export DOCKER_HOST=unix:///var/run/docker.sock to your ~/.bashrc or ~/.bash_profile and reload:

source ~/.bashrc

Upvotes: 0

Ioannis Chrysochos
Ioannis Chrysochos

Reputation: 438

You might be on a different docker context if you're on linux and have Docker Desktop installed. Try running the following command:

docker context use default

And try again whatever you where trying to do before. You might need to start the docker service with

service docker start

In case you want to check all contexts in your machine:

docker context list

And you'll see which ones you can switch to. More detailed info from here:

When installing Docker Desktop, a dedicated "desktop-linux" context is created to interact with Docker Desktop. On startup, Docker Desktop automatically sets its own context (desktop-linux) as the current context. This means that subsequent Docker CLI commands target Docker Desktop. On shutdown, Docker Desktop resets the current context to the default context.

Upvotes: 18

Shahabaj S. Shaikh
Shahabaj S. Shaikh

Reputation: 76

Step 1: run bleow command in terminal 1 same server.

sudo dockerd

Step 2: in terminal 2 same server.

docker ps

It should resolved

Upvotes: 0

Deepanshu Mehta
Deepanshu Mehta

Reputation: 1770

well you can set the Docker CLI to use the local Docker daemon as the current context:

docker context use default

Upvotes: 0

Rahul Gupta
Rahul Gupta

Reputation: 326

LINUX

you can use this answer https://stackoverflow.com/a/33596140/13997503 and even after using this you still get the same error. then you might have previously installed docker desktop and now switching to docker-engine

you can remove the docker desktop service files using this command

$ rm -rf ~/.docker

Upvotes: 7

Ali Amjid
Ali Amjid

Reputation: 51

My problem was, that default path of docker.sock was not where docker daemon was.

My default was /home/user/.docker, but docker daemon was in /var/bin.

i did set env variable to set correct address and that fixed the issue

export DOCKER_CONFIG = '/var/bin'

https://docs.docker.com/engine/reference/commandline/cli/

I installed docker desktop on ubuntu so that might be the issue or why my DOCKER_CONFIG was not set right.

Upvotes: 1

kvadityaaz
kvadityaaz

Reputation: 1491

You can use the command

sudo service docker stop && sudo service docker start

OR

sudo service docker restart

to simply restart it.

Upvotes: 30

kenorb
kenorb

Reputation: 166399

Use Docker CE app

macOS

Use the new Docker Community Edition app for macOS. For example:

  1. Uninstall all Docker Homebrew packages which you've installed so far:

     brew uninstall docker-compose
     brew uninstall docker-machine
     brew uninstall docker
    
  2. Install an app manually or via Homebrew-Cask:

     brew install --cask docker
    

Note: This app will create necessary links to docker, docker-compose, docker-machine, etc.

  1. After running the app, checkout the a Docker whale icon in the status menu.
  2. Now you should be able to use docker, docker-compose, docker-machine commands as usual in the Terminal.

Related:

Linux/Windows

Download the Docker CE from the download page and follow the instructions.

Upvotes: 17

Amr
Amr

Reputation: 653

At April 2020 on MacOS Catalina, you just need to open the desktop application:

docker app running

Upvotes: 9

Max Carroll
Max Carroll

Reputation: 4839

Usually this never happens. But one day the message appeared (as bellow) and a simple reboot fixed it

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

Upvotes: 0

Bill Zelenko
Bill Zelenko

Reputation: 2858

To fix this issue, I had to enable the docker service:

sudo systemctl enable /usr/lib/systemd/system/docker.service

Upvotes: 2

Imre_G
Imre_G

Reputation: 2535

A lot of answers already but in the hope that this helps someone. This is an issue that occurs when you install docker via snap. Running via sudo would allow you to connect to the daemon, but this leads to other issues. The solution is to perform some steps BEFORE you install the snap package making the complete list of steps:

sudo addgroup --system docker
sudo adduser $USER docker
newgrp docker
sudo snap install docker

After doing this, docker will connect to the daemon and work without sudo, no restart required.

https://github.com/docker-archive/docker-snap/issues/1#issuecomment-423778054

Upvotes: 1

Remolten
Remolten

Reputation: 2682

With Docker installed with snap, I sometimes encounter the OP's error upon rebooting my machine. In my case, running sudo snap logs docker revealed an error in the logs:

Error starting daemon: pid file found, ensure docker is not running or delete /var/snap/docker/423/run/docker.pid

After running sudo rm /var/snap/docker/423/run/docker.pid, I can start Docker normally.

Upvotes: 0

Prakasam Dhamodhiran
Prakasam Dhamodhiran

Reputation: 91

I knew that there are plenty of answers already in this post. Just I would like to add one simple answer that is solved the above mentioned problem .

sudo systemctl start docker

Run the above command and it will start all the docker related threads/services.

Upvotes: 8

Tobias Ernst
Tobias Ernst

Reputation: 4634

If you use gitlab-ci / gitlab-runners you get that error if you don't have permissions to access /var/run/docker.sock.

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

To solve the problem:

sudo usermod -aG docker gitlab-runner

Verify with:

sudo -u gitlab-runner -H docker info

Hope that helps.

Upvotes: 1

nPcomp
nPcomp

Reputation: 9843

This usually happens when you are not in the docker group. You can add yourself to the docker group with:

sudo usermod -aG docker yourusername

or

sudo usermod -aG docker $(whoami)

After this, you need to logout and log back into the server.

Alternatively, you can sudo every Docker command.

Upvotes: 53

kenorb
kenorb

Reputation: 166399

Linux

To run docker daemon on Linux (from CLI), run:

$ sudo service docker start # Ubuntu/Debian

Note: Skip the $ character when copy and pasting.

On RedHat/CentOS, run: sudo systemctl start docker.

To initialize the "base" filesystem, run:

$ sudo service docker stop
$ sudo rm -rf /var/lib/docker
$ sudo service docker start

or manually like:

$ sudo docker -d --storage-opt dm.basesize=20G

Install docker-machine on Linux

To install machine binaries on Linux:

  • locally:

    install -vm755 <(curl -L https://github.com/docker/machine/releases/download/v0.5.3/docker-machine_linux-amd64) $HOME/bin/docker-machine
    
  • global:

    sudo bash -c 'install -vm755 <(curl -L https://github.com/docker/machine/releases/download/v0.5.3/docker-machine_linux-amd64) /usr/local/bin/docker-machine'
    

macOS

On macOS the docker binary is only a client and you cannot use it to run the docker daemon, because Docker daemon uses Linux-specific kernel features, therefore you can’t run Docker natively in OS X. So you have to install docker-machine in order to create VM and attach to it.

Install docker-machine on macOS

If you don't have docker-machine command yet, install it by using one of the following methods:

  • Using Brew command: brew install docker-machine docker.
  • manually from GitHub:

    install -v <(curl https://github.com/docker/machine/releases/download/v0.5.3/docker-machine_linux-amd64) /usr/local/bin/docker-machine
    

See: Get started with Docker for Mac.

Configure docker-machine on macOS

To start Docker Machine via Homebrew, run:

brew services start docker-machine

To create a default machine (if you don't have one, see: docker-machine ls):

docker-machine create --driver virtualbox default

Then set-up the environment for the Docker client:

eval "$(docker-machine env default)"

Then double-check by listing containers:

docker ps

See: Get started with Docker Machine and a local VM.


Install Docker.app on macOS

Alternatively to above solution, you can install a Docker app by:

brew cask install docker

Check this post for more details. See also: Cannot connect to the Docker daemon on macOS

Upvotes: 217

SmallChess
SmallChess

Reputation: 8116

On the Mac OS-X, this could just mean the docker installation is out-dated or not running. Simply download the latest docker from the offical site and install it.

Worked for me.

Upvotes: 0

molavec
molavec

Reputation: 9117

Linux

The Post-installation steps for Linux documentation reveals the following steps:

  1. Create the docker group.
    sudo groupadd docker
  2. Add the user to the docker group.
    sudo usermod -aG docker $(whoami)
  3. Log out and log back in to ensure docker runs with correct permissions.
  4. Start docker.
    sudo service docker start

Mac OS X

As Dayel Ostraco says is necessary to add environments variables:

docker-machine start # Start virtual machine for docker
docker-machine env  # It's helps to get environment variables
eval "$(docker-machine env default)" # Set environment variables

The docker-machine start command outputs the comments to guide the process.

Upvotes: 790

Farhood Hosseinpour
Farhood Hosseinpour

Reputation: 153

you can run the daemon with the following command:

sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock &

The script leaves the daemon running in the background, and with the Docker ready you can test that it is accepting commands.

sudo docker info

for more information check this out: https://www.upcloud.com/support/how-to-configure-docker-swarm/

Upvotes: 1

Aamir M Meman
Aamir M Meman

Reputation: 1831

The Docker Service may not be running.

If you are on a RedHat/Fedora/CentOS, please try this:

sudo systemctl start docker

If you are on Ubuntu/Debian:

sudo service start docker

Docker will start running on your host and respective port.

Upvotes: 3

Erich
Erich

Reputation: 2062

I had a similar issue.

In my case the solution was to remove a deprecated version of docker. This I assume was causing some conflicts.

On ubuntu:

sudo apt remove docker

solved the problem for me

Upvotes: 1

Deko
Deko

Reputation: 1058

I just had the same issue, running on Amazon AWS.

Here's what I attempted:

  • Set up docker-machine locally with already existing AWS instance
  • Used generic setup
  • It kind of connected, but since the remote port was closed, it failed
  • After that, the Docker daemon refused to start up, but running dockerd did work...

It was tested following on the remote machine:

service docker start # Also restart, no success
systemctl start docker # Also restart, no success
dockerd # Success

I removed /var/lib/docker and uninstalled everything, but there was no success after reinstallation. Unfortunately I have no logs stored from failures, but docker.service just refused to start.

However, what finally solved my issue was basically:

sudo usermod -aG docker $(whoami)

Upvotes: 5

kevthanewversi
kevthanewversi

Reputation: 3756

If all the other solutions above don't work you can try checking the ownership of /var/run/docker.sock:

ls -l /var/run/docker.sock

If you're not the owner then change ownership with the command:

sudo chown *your-username* /var/run/docker.sock

Then you can go ahead and try executing the Docker commands hassle-free :D

Upvotes: 43

dormi330
dormi330

Reputation: 1353

Try adding the current user to docker group:

sudo usermod -aG docker $USER

Then log out and login.

Upvotes: 7

Shawn Wang
Shawn Wang

Reputation: 791

If you get the message Can't connect to docker daemon. Is 'docker -d' running on this host?, you can check it by docker version.

If you see the information like Docker Client is running. but Docker Server is not, it's obviously you need to start the Docker server.

In CentOS, you can use service to start or stop the Docker server.

$ sudo service docker stop
$ sudo service docker start

Then, after you type docker version, you will get the information of Docker Client and Docker Server, and the Docker daemon has been started.

Upvotes: 16

Taha Emara
Taha Emara

Reputation: 140

I have faced this problem, and I restarted Docker using these commands:

$ sudo service docker stop
$ sudo service docker start

But I did not solve my problem, because I forgot to execute my Docker commands without sudo. For those who faces this problem, try to check that.

Try

$ sudo docker info

instead of this:

$ docker info

Upvotes: 9

Ermias K
Ermias K

Reputation: 106

If you are running on OS X using Docker tool, follow this.

Restart the daemon and configure your environment:

docker-machine restart

And then

docker-machine env

Finally,

eval $(docker-machine env)

To test the daemon is running:

docker ps -a or docker-machine ls. This will list all containers.

Upvotes: 4

Galley
Galley

Reputation: 633

I restart Docker after installing it:

$ sudo service docker stop
$ sudo service docker start

And it works.

Upvotes: 12

Related Questions