简体   繁体   English

无法连接到位于 unix:/var/run/docker.sock 的 Docker 守护程序。 docker 守护程序是否正在运行?

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

I have applied every solution available on inte.net but still I cannot run Docker.我已经应用了 inte.net 上可用的所有解决方案,但仍然无法运行 Docker。

I want to use Scrapy Splash on my server.我想在我的服务器上使用 Scrapy Splash。

Here is history of commands I ran.这是我运行的命令的history

docker run -p 8050:8050 scrapinghub/splash
sudo docker run -p 8050:8050 scrapinghub/splash
sudo usermod -aG docker $(whoami)
sudo docker run -p 8050:8050 scrapinghub/splash
newgrp docker
sudo docker run -p 8050:8050 scrapinghub/splash
reboot
sudo docker run -p 8050:8050 scrapinghub/splash
docker run -p 8050:8050 scrapinghub/splash

You can see I tried to restart my server as well, but it didnt help.你可以看到我也尝试重新启动我的服务器,但没有帮助。

see output of ps -aux | grep docker参见 output 的ps -aux | grep docker ps -aux | grep docker

root@mani:/var/www/html# ps aux | grep docker
root      8524  0.0  0.8 127904 13964 ?        Ssl  17:21   0:00 /usr/bin/dockerd --raw-logs
root      8534  0.0  0.3  90588  5012 ?        Ssl  17:21   0:00 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
root      8543  0.0  0.0   8812   764 pts/1    S+   17:21   0:00 grep --color=auto docker
root     16356  0.0  0.0  17200   964 pts/1    S    17:14   0:00 newgrp docker
root     20080  0.0  0.0  17200   964 pts/1    S    17:06   0:00 newgrp docker
root     30221  0.0  0.0  17200   964 pts/1    S    17:09   0:00 newgrp docker

but it gives the error:但它给出了错误:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock .无法连接到位于unix:///var/run/docker.sock的 Docker 守护进程。 Is the docker daemon running?. docker 守护程序是否正在运行?

You can try out this:你可以试试这个:

systemctl start docker

It worked fine for me.它对我来说很好。

PS: after if there is commands that you can't do without sudo, try this: PS:如果有没有sudo不能执行的命令,试试这个:

gpasswd -a $USER docker

Just Run赶紧跑

sudo dockerd

dockerd is the daemon service for docker containers, because it is not running in background we're not able to take any actions related to the service, which needs be restarted. dockerd 是 docker 容器的守护程序服务,因为它不在后台运行,我们无法采取与服务相关的任何操作,需要重新启动。

You can get this error if docker doesn't shut down cleanly.如果 docker 没有完全关闭,您可能会收到此错误。 The following answer is for the docker snap package.以下答案适用于 docker snap 包。

Run snap logs docker and look for the following:运行snap logs docker并查找以下内容:

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

Deleting that file and restarting docker worked for me.删除该文件并重新启动 docker 对我有用。

rm /var/snap/docker/<your-version-number>/run/docker.pid
snap stop docker
snap start docker

Make sure to replace ‍‍‍‍ <your-version-number>‍ with the appropriate version number.确保将<your-version-number>‍为适当的版本号。

I just hit this after doing a fresh install of DOCKER from the main docs.在从主文档中重新安装 DOCKER 后,我刚刚点击了这个。 The problem for me was that immediately after the install, the service is not running.对我来说,问题是安装后立即服务没有运行。

These commands will help you to make sure docker is up and running for your run command to find it:这些命令将帮助您确保 docker 已启动并运行,以便您的运行命令找到它:

$ sudo service --status-all 
$ sudo service docker start
$ sudo service docker start

Easy way to fix this issue, try this解决这个问题的简单方法,试试这个

sudo su
systemctl start docker
systemctl enable docker
systemctl restart docker

First, try with sudo , as the current user may not have access permissions to communicate to docker daemon ie:首先,尝试使用sudo ,因为当前用户可能没有与 docker daemon 通信的访问权限,即:

/var/run/docker.sock

If its still not working, then, after the installation, simply stop the docker daemon:如果它仍然无法正常工作,那么在安装后,只需停止 docker 守护进程:

sudo service docker stop

And, run the following command to start the daemon in background:并且,运行以下命令在后台启动守护进程:

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

To make working with Docker easier, you should add your username to the Docker users group.为了更轻松地使用 Docker,您应该将您的用户名添加到 Docker 用户组。 Adding a user to the group can be done with the command below:可以使用以下命令将用户添加到组中:

sudo usermod -aG docker $USER

Also, this step is mentioned in the official documentation of docker Post-installation steps for Linux.另外,Linux 的 docker Post-installation steps 官方文档中也提到了这一步。

Ubuntu 16.04 users can follow these steps: Ubuntu 16.04用户可以按照以下步骤操作:

Inside file /lib/systemd/system/docker.service change:内部文件/lib/systemd/system/docker.service更改:

ExecStart=/usr/bin/dockerd fd://

to

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375

Inside file /etc/init.d/docker change:内部文件/etc/init.d/docker更改:

DOCKER_OPTS=

to

DOCKER_OPTS="-H tcp://0.0.0.0:2375"

and then restart your machine, and start playing with docker.然后重启你的机器,开始玩docker。

在此处输入图像描述

I just simply forget running the Docker Desktop in my mac, after running Docker Desktop, you will be good to go.我只是忘记在我的 mac 上运行 Docker Desktop,运行 Docker Desktop 之后,你就可以开始了。

This usually happened if you haven't stopped docker probably.如果您可能没有停止 docker,通常会发生这种情况。

To resolve解决

service docker stop
cd /var/run/docker/libcontainerd
rm -rf containerd/*
rm -f docker-containerd.pid
service docker start

then "docker run...." to download your image and start the container as usual然后“docker run ....”下载你的图像并像往常一样启动容器

It's worked for me:它对我有用:

sudo systemctl unmask docker
sudo systemctl start docker

这对我来说很好..!

service docker restart

我想如果您使用带有 GUI 的 WSL,那么您可以尝试

sudo /etc/init.d/docker start

I had this problem after closing docker while pulling a container:在拉动容器时关闭 docker 后我遇到了这个问题:

docker pull mongo

At first I was getting weird errors so I purged docker:起初我遇到了奇怪的错误,所以我清除了 docker:

sudo apt-get purge docker.io

and reinstalled:并重新安装:

sudo apt-get install docker.io

All of this did nothing;所有这一切都无济于事。 I couldn't even run the "hello-world" container.我什至无法运行“hello-world”容器。

The correct fix, for me at least was:至少对我来说,正确的解决方法是:

systemctl unmask docker.service
systemctl unmask docker.socket
systemctl start docker.service

After this I could pull mongo and run "hello world".在此之后,我可以拉 mongo 并运行“hello world”。

On Ubuntu 20.04 and Docker version 20.10.11,as a non root user, Running:在 Ubuntu 20.04 和 Docker 版本 20.10.11 上,作为非 root 用户,运行:

sudo service docker start

Then checking the status然后查看状态

sudo service docker status

Shows节目

* Docker is running

But trying any docker command such as但是尝试任何 docker 命令,例如

docker images

Shows the same error显示相同的错误

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

Running the below solves it运行以下解决它

sudo service docker restart

Restart solved it, while start did not重启解决了,而启动没有

I'm running on root and tried below, it worked:我在root上运行并在下面尝试,它有效:

service docker start

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

It happens by the docker is not started yet.它发生在 docker 尚未启动。

Please check the docker status请检查码头工人状态

$ sudo systemctl status docker

Then start and enable the docker and recheck the status然后启动并启用 docker 并重新检查状态

$ sudo systemctl start docker && sudo systemctl enable docker && sudo systemctl status docker

Thats it.而已。 Now the last step for checking the docker is working fine现在检查 docker 的最后一步工作正常

$ sudo docker run hello-world

here's the solution which works for me on Linux这是在 Linux 上对我有用的解决方案

systemctl start docker . systemctl start docker

for linux run对于 linux 运行

sudo dockerd

However, if you use Docker Client for mac it won't work.但是,如果您使用 Docker Client for mac,它将无法正常工作。 try the below code试试下面的代码

$socat TCP-LISTEN:2376,reuseaddr,fork UNIX-CLIENT:/var/run/docker.sock

https://forums.docker.com/t/using-pycharm-docker-plugin-with-docker-beta/8617/9 https://forums.docker.com/t/using-pycharm-docker-plugin-with-docker-beta/8617/9

That workaround opens port 2376 to the world... as TLS isn't enabled, this is a bad idea as anyone on the same network can hijack your docker daemon该解决方法将端口 2376 向全世界开放...由于未启用 TLS,这是一个坏主意,因为同一网络上的任何人都可以劫持您的 docker 守护进程

I also received the error message below, after installing the docker and running: docker run hello-world #Cannot connect to the Docker daemon at unix: /var/run/docker.sock.在安装 docker 并运行后,我还收到以下错误消息:docker run hello-world #Cannot connect to the Docker daemon at unix: /var/run/docker.sock。 Is the docker daemon running? docker 守护进程是否正在运行?

Here's a solution, what worked for me.这是一个解决方案,对我有用。 Environment环境

  • Windows 10 (Don't forget to enable on windows: Settings> Update and Security> Developer mode) Windows 10(别忘了在 Windows 上启用:设置>更新和安全>开发者模式)
  • Ubuntu 18.04 LTS Ubuntu 18.04 LTS
  • Docker Desktop version 2.3.0.2 (45183) Docker 桌面版 2.3.0.2 (45183)
    • Enable in Docker Desktop: Expose daemon on tcp: // localhost: 2375 without TLS在 Docker 桌面中启用:在 tcp 上公开守护进程:// localhost: 2375 without TLS
    • Docker Desktop must also be running (connected to Docker Hub ... just log in) Docker Desktop 也必须正在运行(连接到 Docker Hub ... 只需登录)

After installing ubuntu, update the repository安装 ubuntu 后,更新存储库

sudo apt-get update

To use a repository over HTTPS通过 HTTPS 使用存储库

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Add the official Docker GPG key:添加官方 Docker GPG 密钥:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Make sure you now have the key with the fingerprint确保您现在拥有带指纹的钥匙

sudo apt-key fingerprint 0EBFCD88

Update the repository更新存储库

sudo apt-get update

Update the docker repository更新 docker 存储库

sudo add-apt-repository "deb [arch = amd64] https://download.docker.com/linux/ubuntu $ (lsb_release -cs) stable "

Update the repository again再次更新存储库

sudo apt-get update

Command to install the docker in version: 5: 18.09.9 ~ 3-0 ~ ubuntu-bionic安装 docker 版本的命令:5: 18.09.9 ~ 3-0 ~ ubuntu-bionic

sudo apt-get install docker-ce = 5: 18.09.9 ~ 3-0 ~ ubuntu-bionic docker-ce-cli = 5: 18.09.9 ~ 3-0 ~ ubuntu-bionic containerd.io

Command to set the DOCKER_HOST设置 DOCKER_HOST 的命令

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

Note: put the command above in your profile to start with the ubunto ex: echo "export DOCKER_HOST="tcp://0.0.0.0:2375"" >> ~/.bashrc注意:将上面的命令放在您的配置文件中以启动 ubunto ex:echo "export DOCKER_HOST="tcp://0.0.0.0:2375"" >> ~/.bashrc

Add user to the docker group将用户添加到 docker 组

sudo usermod -aG docker $USER

Restart ubuntu重启ubuntu

(Close and open the ubuntu window again) or run: (关闭并再次打开 ubuntu 窗口)或运行:

source ~/.bashrc

Testing the installation (DO NOT use more sudo before docker commands (it will give an error), the user "root" has already been included in the docker group)测试安装(不要在 docker 命令之前使用更多的 sudo(它会出错),用户“root”已经包含在 docker 组中)

docker run hello-world

The message below should be displayed应显示以下消息

Hello from Docker!来自 Docker 的您好! This message shows that your installation appears to be working correctly.此消息表明您的安装似乎工作正常。

Note: if it fails, run the command again:注意:如果失败,请再次运行命令:

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

Reference: https://docs.docker.com/engine/install/ubuntu/ Session: INSTALL DOCKER ENGINE参考: https ://docs.docker.com/engine/install/ubuntu/ 会话:安装 DOCKER ENGINE

#For other versions of the docker that can be installed with ubuntu, see the repository using the command below: apt-cache madison docker-ce #其他可以用ubuntu安装的docker版本,使用以下命令查看仓库:apt-cache madison docker-ce

Then install the desired version of the docker:然后安装所需版本的 docker:

sudo apt-get install docker-ce = <VERSION_STRING> docker-ce-cli = <VERSION_STRING> containerd.io

如果您使用的是 MAC,那么只需在 finder 中输入 docker,它就会自动解析。

Make sure information in this path /etc/docker/daemon.json确保此路径/etc/docker/daemon.json中的信息

{
  "registry-mirror": [
    "https://registry.docker-cn.com"
  ],
  "insecure-registries": [
    "192.168.199.100:5000"
  ]
}

delete删除

"insecure-registries": [
    "192.168.199.100:5000"
]

and runs well enter image description here并且运行良好在此处输入图像描述

I installed docker from snap repository.我从快照存储库安装了 docker。 So I also had to start from snap (running Ubuntu).所以我也不得不从 snap(运行 Ubuntu)开始。

sudo snap start docker

Otherwise you can also install it from their repositories .否则,您也可以从他们的存储库安装它。

2022 Solution 2022解决方案

This work by my side:我身边的这项工作:

Add the below in your volume:在您的卷中添加以下内容:

volumes:
 - "/var/run/docker.sock:/var/run/docker.sock"

after that execute the below command之后执行以下命令

 sudo  chown 1000:1000 /var/run/docker.sock

Please note 1000 is the ID of the user.请注意 1000 是用户的 ID。 to know it execute the below command:要知道它执行以下命令:

id

I was trying to run docker(just installed) in an instance of AWS when the message appears.当消息出现时,我试图在 AWS 实例中运行 docker(刚刚安装)。 I just write sudo service docker start and works fine for me.我只是写了sudo service docker start并且对我来说很好。

Also see AWS with Docker另请参阅AWS 与 Docker

This exception comes when the service of docker is not running or the logged in user dont have the permission to access docker and generally it comes in RedHat当 docker 的服务没有运行或登录的用户没有访问 docker 的权限时会出现此异常,通常它来自 RedHat

Using below command should resolve the issue使用以下命令应该可以解决问题

sudo service docker start须藤服务码头工人开始

在此处输入图像描述

This works in my case:这适用于我的情况:

sudo service docker start

I had the same problem for gitlab CI running node:lts image:我对运行 node:lts 图像的 gitlab CI 有同样的问题:

  • I just restarted the docker daemon and restart the container, it worked for me.我刚刚重新启动了 docker 守护进程并重新启动了容器,它对我有用。

在 ubuntu 中使用它 export DOCKER_HOST=tcp://localhost:2375

export DOCKER_HOST=tcp://localhost:2375 非常适合没有 sudo 访问权限且用户无权访问 unix:///var/run/docker.sock 的任何人

It could be related to no disk space left on the hard drive.这可能与硬盘驱动器上没有剩余磁盘空间有关。 Make sure you have space left on the device, Docker can't start up if there isn't any space left.确保设备上有剩余空间,如果没有剩余空间,Docker 将无法启动。

None of the current answers worked for my version of this error.当前的答案都不适用于我的此错误版本。 I'm using the desktop version of Ubuntu 18. The following two commands fixed the issue.我使用的是 Ubuntu 18 的桌面版本。以下两个命令解决了这个问题。

sudo snap connect docker:home :home

sudo snap start docker

In root mode, run the command systemctl start docker在 root 模式下,运行命令systemctl start docker

And afterwards, you can check the status by running systemctl status docker之后,您可以通过运行systemctl status docker

I had this problem when docker was started after my terminal was started.在我的终端启动后启动 docker 时我遇到了这个问题。 Restarting the terminal or the process hosting the terminal (such as vscode) resolved the issue.重新启动终端或托管终端的进程(例如 vscode)解决了该问题。

If you are trying to install docker with wsl 2 linux subsystem in windows, please read this document and check whether this command is executed:如果您尝试在 windows 中安装带有 wsl 2 linux 子系统的 docker,请阅读文档并检查是否执行了此命令:

wsl.exe --set-version (distro name) 2

and also check in your Windows OS docker->settings->Resources->Enable integration with additional distros: are checked on and restarted.并检查您的 Windows 操作系统docker->settings->Resources->Enable integration with additional distros: 检查并重新启动。

I faced same issue on Linux when I installed docker using yum (yum install docker).当我使用 yum (yum install docker) 安装 docker 时,我在 Linux 上遇到了同样的问题。

Resolution: download docker binary from official site: docker install , unpack and follow the installation steps.解决方法:从官方网站下载 docker 二进制文件: docker install ,解压并按照安装步骤操作。

This might be a bit late for you but hope it will help someone find their way through the docker jungles.这对你来说可能有点晚了,但希望它能帮助人们在码头丛林中找到自己的路。 The problem might be coming from a tcp port binding issue verify if this file exists问题可能来自 tcp 端口绑定问题,请验证此文件是否存在

/etc/systemd/system/docker.service.d /etc/systemd/system/docker.service.d

this is the default UNIX socket listening override file.这是默认的 UNIX 套接字侦听覆盖文件。 The file might actauly be empty, but i find that the fact that it exists sometimes causes some headaches like what you faced.该文件可能实际上是空的,但我发现它存在的事实有时会导致一些头痛,就像你所面临的那样。 if it exists 1. then 2. if not just go straight to 2.如果它存在 1. 那么 2. 如果不直接去 2.

1. $ sudo rm -rf /etc/systemd/system/docker.service.d

2. $ sudo systemctl deamon-reload

I find that some of the recommendations here overlook the error being in the actual daemon failing to load我发现这里的一些建议忽略了实际守护程序无法加载的错误

A good friend when playing with docker is玩docker的好朋友是

$ systemctl status docker.service

For those fresh installing & trying to running docker on RaspberryPi (RPi) like me, I needed to reboot my RPi 4B+ to resolve this issue and actually run the docker daemon.对于那些像我一样在 RaspberryPi (RPi) 上新安装并尝试运行 docker 的人,我需要重新启动我的 RPi 4B+ 来解决这个问题并实际运行 docker 守护进程。

By the time of writing this contribution this great manual does mention the necessity to reboot RPi, but only after setting "Non root-user to the Docker Group".在撰写这篇文章时,这本很棒的手册确实提到了重启 RPi 的必要性,但只是在将“非 root 用户设置为 Docker 组”之后。

HTH, should someone miss this like me.. HTH,如果有人像我一样想念这个..

To me docker was really not running missing the following command to start it:对我来说 docker 确实没有运行缺少以下命令来启动它:

systemctl --user start docker-desktop

for me the cause of the error was docker desktop i had forced quit it.对我来说,错误的原因是 docker 桌面,我强行退出了它。 so restarting docker desktop worked for me and error got resolved.所以重新启动 docker 桌面对我有用并且错误得到解决。

on windows 11 with ubuntu 22 the command wsl.exe --update in power shell helped me to run docker through containerd as it was on windows 10在 windows 11 和 ubuntu 22 命令wsl.exe --update in power shell 帮助我通过 containerd 运行 docker,因为它在 windows 10

before that i was getting Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running在此之前,我Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running which wasn't happend to me on windows 10 ubuntu 20.04 with the same set up. Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running ,而我在 windows 10 ubuntu 20.04 上并没有发生相同的设置。

starting with ordinary sudo service docker start从普通sudo service docker start

This worked for me, It might just work for you if you are using Ubuntu 16 or 18 (14 may also work).这对我有用,如果你使用的是 Ubuntu 16 或 18(14 也可能工作),它可能只对你有用。 Easy to give a try:轻松尝试:

Go to Ubuntu Software, type in Docker.转到 Ubuntu 软件,输入 Docker。 Uninstall docker (108 mb) if it is preinstalled there.如果 docker (108 mb) 预装在那里,请卸载它。 Install docker Now run the commands and see if the same error comes安装 docker 现在运行命令,看看是否出现同样的错误

The error:错误:

在此处输入图像描述

After doing the above steps.完成以上步骤后。 在此处输入图像描述

As you can see, it worked:)如您所见,它起作用了:)

For me the solution was to simply make sure I had installed the correct Docker package.对我来说,解决方案只是确保我安装了正确的 Docker 包。 For example, for Ubuntu the depreciated packages are:例如,对于 Ubuntu,折旧的软件包是:

  • docker码头工人
  • docker-engine码头引擎
  • docker.io码头工人.io
  • containerd容器化
  • runc运行

For installation check https://docs.docker.com .对于安装检查https://docs.docker.com Instructions are provided for Ubuntu , CentOS , Debian and Fedora at the time of writing.在撰写本文时,已为UbuntuCentOSDebianFedora提供了说明。

For everyone who is having problems with Docker at the time of installation.对于在安装时遇到 Docker 问题的每个人。

An error pointing to a failure in the docker service, do the commands below.指向 docker 服务失败的错误,请执行以下命令。

$ sudo apt update

$ sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common

$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"

$ sudo apt update

$ apt-cache policy docker-ce

$ sudo apt install docker-ce

I had the same issue.我遇到过同样的问题。 In my case, VPN was the culprit.就我而言,VPN 是罪魁祸首。 Turning off the VPN helped with the successful installation.关闭 VPN 有助于成功安装。

Just adding to the knowledge base.只是添加到知识库。 I found this video helpful.我发现这个视频很有帮助。 I do not have DOCKER_HOST defined.我没有定义DOCKER_HOST I do have a /etc/wsl.conf that has:我确实有一个/etc/wsl.conf有:

[automount]
root = /
options = "metadata"

After Restarting a few times docker hello-world worked.重启几次后,docker hello-world 工作了。

I didn't see this solution mentioned, so I'll post it in case it might help someone.我没有看到提到这个解决方案,所以我会发布它以防它可能对某人有所帮助。 I was running into this error on my MacOS machine.我在我的 MacOS 机器上遇到了这个错误。 The reason was that I had the DOCKER_HOST environment variable set in my dotfiles.原因是我在我的点文件中设置了DOCKER_HOST环境变量。 Unsetting it through unset DOCKER_HOST did the trick.通过unset DOCKER_HOST就可以了。 I found the tip in the official docker for Mac documentation: https://docs.docker.com/desktop/mac/troubleshoot/#workarounds-for-common-problems .我在官方 docker for Mac 文档中找到了提示: https ://docs.docker.com/desktop/mac/troubleshoot/#workarounds-for-common-problems。

I read through all the answers and didn't find anything close to my situation.我通读了所有答案,没有发现任何与我的情况相近的东西。 In the end, the problem turned out to be that docker was installed twice on my system, once on snap , and another time through the convenience script.最后,问题原来是docker在我的系统上安装了两次,一次是在snap上,另一次是通过便利脚本。 So, if anybody runs into this problem, make sure to check that docker isn't installed in multiple places because that can cause some really weird behavior.因此,如果有人遇到此问题,请务必检查docker是否安装在多个位置,因为这可能会导致一些非常奇怪的行为。

I am using Ubuntu 22.04.我正在使用 Ubuntu 22.04。 After doing a lot of research and going through lot of websites, I found that running docker as non root user is taking a different context.在做了很多研究并浏览了很多网站之后,我发现以非 root 用户身份运行 docker 会采用不同的上下文。 Using the below commands solved my issue..使用以下命令解决了我的问题..

docker context ls 
docker context use default 

On Ubuntu 22 "sudo service docker start" worked for me.在 Ubuntu 22 “sudo service docker start”上为我工作。

vikaspiprade@AUMEL-P7750-VP:~$ sudo docker run hello-world
docker: Cannot connect to the Docker daemon at 
unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
vikaspiprade@AUMEL-P7750-VP:~$ sudo /var/run/docker.sock
sudo: /var/run/docker.sock: command not found
vikaspiprade@AUMEL-P7750-VP:~$ /var/run/docker.sock
-bash: /var/run/docker.sock: Permission denied
vikaspiprade@AUMEL-P7750-VP:~$ sudo service docker stop
* Docker already stopped - file /var/run/docker-ssd.pid not found.
vikaspiprade@AUMEL-P7750-VP:~$ sudo service docker start
* Starting Docker: docker                                                                                       
[ OK ]
vikaspiprade@AUMEL-P7750-VP:~$

在此处输入图像描述

I had this error message when I was not logged into Docker. Before more advanced troubleshooting, make sure you're logged into Docker. On mac, open the Docker Desktop app and sign in. This fixed the error for me.当我没有登录 Docker 时收到此错误消息。在进行更高级的故障排除之前,请确保您已登录 Docker。在 Mac 上,打开 Docker 桌面应用程序并登录。这为我修复了错误。

make sure VPN in turned off when starting docker service确保在启动 docker 服务时关闭 VPN

Docker.sock works as a channel to communicate between docker CLI and docker daemon. Docker.sock 作为 docker CLI 和 docker 守护进程之间通信的通道。 You can simply run your container by using this command.您可以使用此命令简单地运行您的容器。

docker run -v /var/run/docker.sock:/var/run/docker.sock  <ImageName>:latest

In my case when doing sudo dockerd --debug it showed this error: " failed to start daemon: Error initializing.network controller: error obtaining controller instance: failed to create NAT chain DOCKER: Iptables not found "在我做sudo dockerd --debug的情况下,它显示了这个错误:“ failed to start daemon: Error initializing.network controller: error obtaining controller instance: failed to create NAT chain DOCKER: Iptables not found

To solve it I put:为了解决它,我把:

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
sudo systemctl start docker.service

For more details you can check: https://forums.docker.com/t/failing-to-start-dockerd-failed-to-create-nat-chain-docker/78269更多详情可以查看: https://forums.docker.com/t/failing-to-start-dockerd-failed-to-create-nat-chain-docker/78269

Assign Ownership to the Docker Unix Socket将所有权分配给 Docker Unix 套接字

The “cannot connect to the Docker daemon” error also happens if the Unix socket file for Docker doesn't have the correct ownership assigned.如果 Docker 的 Unix 套接字文件没有分配正确的所有权,也会发生“无法连接到 Docker 守护程序”错误。

1. Check ownership for the Docker Unix socket: 1. 检查 Docker Unix 套接字的所有权:

sudo ls -la /var/run/docker.sock

在此处输入图像描述

2. If necessary, grant the user ownership with: 2. 如有必要,授予用户所有权:

sudo chown [username]:docker /var/run/docker.sock

Credits to Phonenixnap For answer感谢Phonenixnap的回答

这个问题可以通过运行 1.systemctl enable docker 2.service docker start 永久解决

Use docker start <your_container_name>使用docker start <your_container_name>

Then connect to database by using mssql -u <yourUsername> -p <yourPassword>然后使用mssql -u <yourUsername> -p <yourPassword>连接到数据库

If you get an error in the first step then the docker is running and go with the second step.如果您在第一步中遇到错误,则 docker 正在运行并继续执行第二步。

Note: I use Mac as my primary OS and this might be the same answer for Unix based OSs.注意:我使用 Mac 作为我的主要操作系统,这可能与基于 Unix 的操作系统的答案相同。 If not!如果不! Sorry in advance.提前抱歉。

Just restarting the system worked for me.只是重新启动系统对我有用。 It might be a temporary issue可能是暂时的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM