我通常喜欢在我的OSX上用brew管理我的应用程序

我能够安装docker, docker-compose和docker-machine

docker --version
Docker version 17.05.0-ce, build 89658be
docker-compose --version
docker-compose version 1.13.0, build unknown
docker-machine --version
docker-machine version 0.11.0, build 5b27455

我没有下载并运行“Docker for Mac”应用程序。

然而,当我试图跑

> docker run -d -p 80:80 --name webserver nginx
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

我已经检查了袜子档案

ls -lah /var/run/docker.sock /var/tmp/docker.sock
ls: /var/run/docker.sock: No such file or directory
ls: /var/tmp/docker.sock: No such file or directory

我也尝试了这个建议的解决方案:Mac OS X sudo docker无法连接到docker守护进程。这个主机上是否运行docker守护进程?

但是我收到了这个错误信息:

$ eval $(docker-machine env default)
Host does not exist: "default"

有可能通过命令行工具来运行docker服务吗?


当前回答

尝试以下,它的工作现在很好

$ docker-machine create default
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Found a new host-only adapter: "vboxnet0"
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!

Then

$ docker-machine env default

最后

$ eval $(docker-machine env default)
$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

其他回答

尝试以下,它的工作现在很好

$ docker-machine create default
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Found a new host-only adapter: "vboxnet0"
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!

Then

$ docker-machine env default

最后

$ eval $(docker-machine env default)
$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Docker被设计为在Linux上运行。但可以在macOS上的虚拟机中运行。要做到这一点有点费力,这也许就是Docker Desktop存在的首要原因。但这并不意味着你不能在Mac上舒服地使用命令行使用Docker。

一些可以考虑的选项:

您可以使用lima并在bash配置文件中添加别名docker='lima nerdctl'。 您可以在您的机器上安装一个Linux虚拟机并使用它(不推荐)。 Mac上的双引导Linux。现在甚至支持T2和M1芯片的机器。

打开Docker Desktop对我来说很有用。

docker-machine现在已经弃用了,我发现Colima是一个很好的替代品,你可以用一个简单的命令轻松连接docker守护进程:

brew install docker docker-compose colima
# make coffee
colima start

准备docker:

docker run hello-world

这个问题:

$ brew install docker docker-machine
$ docker ps

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

这显然意味着要做到以下几点:

$ docker-machine create default # default driver is apparently vbox:
Running pre-create checks...
Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path"
$  brew cask install virtualbox
…
$ docker-machine create default 
# works this time
$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
$ eval "$(docker-machine env default)"
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

它终于成功了。

如果你不想安装虚拟机,你可以使用“xhyve”驱动。 你也可以安装“docker应用程序”(然后运行它),这显然使你不必运行上面的一些。酿造桶安装docker然后运行应用程序,看到其他答案。但显然这本身并不是必要的。