在Docker容器中安装Web应用程序:拨打unix /var/run/docker.sock:没有这样的文件或目录 [英] Installing a web application in a Docker container: dial unix /var/run/docker.sock: no such file or directory

查看:145
本文介绍了在Docker容器中安装Web应用程序:拨打unix /var/run/docker.sock:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Docker容器中安装一个Web应用程序。



我使用的是操作系统X Yosemite版本10.10.1



我一直在关注Dockerizing一个Node.js Web App的教程: https://docs.docker.com/examples/nodejs_web_app/


  1. 我下载并设置boot2docker osx-installer在:github.com/boot2docker/osx-installer/releases/tag/v1.4.1


  2. 我在控制台中输入了这些命令以下顺序:



    $ boot2docker init
    $ boot2docker start
    $(boot2docker shellinit)


  3. 然后按照终端的指示,使用以下命令设置环境变量:



    $ export DOCKER_TLS_VERIFY = 1
    $ export DOCKER_HOST = tcp://192.168.59.103:2376
    $ export DOCKER_CERT_PATH = / Users / myusername / .boot2docker / certs / boot2docker-vm


在这一点上,一切似乎都正常。


  1. 然后,在Dockerizing一个Node.js应用程序的教程之后,我来到这里: https://docs.docker.com/examples/nodejs_web_app/#building-your-image ,其中您输入命令:



    $ sudo docker build -t<您的用户名> / centos-node-hello。


  2. 然后要求输入密码,然后输入后,我会收到以下错误消息:



    发送构建上下文到Docker守护程序
    FATA [0000]发布http:///var/run/docker.sock/v1.16/build?rm = 1& t = myusername %2Fcentos-node- hello:拨打unix /var/run/docker.sock:没有这样的文件或目录


这是我的env变量:

 `TERM_PROGRAM = Apple_Terminal 
TERM = xterm-256c olor
SHELL = / bin / bash
TMPDIR = / var / folders / vb / vmd78vk57mqd6fv7sqb544pc0000gn / T /
DOCKER_HOST = tcp://192.168.59.103:2376
Apple_PubSub_Socket_Render = private / tmp / com.apple.launchd.BBIW525XNA / Render
TERM_PROGRAM_VERSION = 343
OLDPWD = / Users / myusername / Desktop
TERM_SESSION_ID = FAD1F3F1-35DF-4183-A47A-08749EAFEACB
USER = myusername
SSH_AUTH_SOCK = / private / tmp / com.apple.launchd.A6ZjHwx8eq / Listeners
__CF_USER_TEXT_ENCODING = 0x1F5:0x0:0x0
DOCKER_TLS_VERIFY = 1
PATH = /用户/myusername/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
PWD = / Users / myusername / Desktop / docker
LANG = en_CA.UTF-8
vXPC_FLAGS = 0x0
XPC_SERVICE_NAME = 0
DOCKER_CERT_PATH = / Users / myusername / .boot2docker / certs / boot2docker-vm
首页= / Users / myusername
SHLVL = 1
LOGNAME = myusername
DISPLAY = / private / tmp / com.apple.launchd.IesbS7VdCy / org.macosforge.xquartz:0
SECURITYSESSIONID = 186a5
_ = / usr / bin / env`

我的Docker版本:

 `客户端版本:1.4.1 
客户端API版本: 1.16
Go version(client):go1.3.3
Git commit(client):5bc2ff8
OS / Arch(client):darwin / amd64
服务器版本:1.4.1
服务器API版本:1.16
Go版本(服务器):go1.3.3
Git提交(服务器):5bc2ff8`

任何帮助将非常感激。谢谢

解决方案

您的具体案例的简短答案:不要使用 sudo



这就是为什么:



当你使用 boot2docker docker 守护程序在VM中运行,基本上在不同的机器上运行。要在另一台计算机上与 docker 守护进程通信,您必须使用TLS连接(通过HTTPS到守护程序的REST API)。这就是为什么你必须设置 DOCKER_HOST DOCKER_CERT_PATH 。由于守护进程运行在不同的机器上,所以您不需要使用root来与之进行通信,因为传出的http连接不需要root,与尝试与 unix:/// var /run/docker.sock 套接字。



但是当您运行 sudo docker 突然你是一个不同的用户,你是 root 。您设置为常规帐户的环境变量未设置。因此, docker CLI使用其默认通信方式: unix 套接字。套接字不在那里,因为守护进程在不同的计算机上运行( boot2docker vm)。因此出现错误信息。


I'm trying to install a web application in a Docker container.

I'm using OS X Yosemite version 10.10.1

I've been following the tutorial on Dockerizing a Node.js Web App here: https://docs.docker.com/examples/nodejs_web_app/

  1. I downloaded and set up the boot2docker osx-installer at: github.com/boot2docker/osx-installer/releases/tag/v1.4.1

  2. I entered these commands in the console in the following order:

    $ boot2docker init $ boot2docker start $ (boot2docker shellinit)

  3. Then I set the environmental variable, as instructed by the terminal, with the following commands:

    $ export DOCKER_TLS_VERIFY=1 $ export DOCKER_HOST=tcp://192.168.59.103:2376 $ export DOCKER_CERT_PATH=/Users/myusername/.boot2docker/certs/boot2docker-vm

At this point, everything seemed to be working alright.

  1. Then, following the tutorial on Dockerizing a Node.js app, I got to the point here: https://docs.docker.com/examples/nodejs_web_app/#building-your-image, where you enter the command:

    $ sudo docker build -t <your username>/centos-node-hello .

  2. Then is asks for a password, and then after entering it I keep getting this error message:

    Sending build context to Docker daemon FATA[0000] Post http:///var/run/docker.sock/v1.16/build?rm=1&t=myusername%2Fcentos-node- hello: dial unix /var/run/docker.sock: no such file or directory

Here are my env variables:

`TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/vb/vmd78vk57mqd6fv7sqb544pc0000gn/T/
DOCKER_HOST=tcp://192.168.59.103:2376
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.BBIW525XNA/Render
TERM_PROGRAM_VERSION=343
OLDPWD=/Users/myusername/Desktop
TERM_SESSION_ID=FAD1F3F1-35DF-4183-A47A-08749EAFEACB
USER=myusername
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.A6ZjHwx8eq/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
DOCKER_TLS_VERIFY=1
PATH=/Users/myusername/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
PWD=/Users/myusername/Desktop/docker
LANG=en_CA.UTF-8
vXPC_FLAGS=0x0
XPC_SERVICE_NAME=0
DOCKER_CERT_PATH=/Users/myusername/.boot2docker/certs/boot2docker-vm
HOME=/Users/myusername
SHLVL=1
LOGNAME=myusername
DISPLAY=/private/tmp/com.apple.launchd.IesbS7VdCy/org.macosforge.xquartz:0
SECURITYSESSIONID=186a5
_=/usr/bin/env`

My Docker version:

`Client version: 1.4.1
Client API version: 1.16
Go version (client): go1.3.3
Git commit (client): 5bc2ff8
OS/Arch (client): darwin/amd64
Server version: 1.4.1
Server API version: 1.16
Go version (server): go1.3.3
Git commit (server): 5bc2ff8`

Any help would be really appreciated. Thanks

解决方案

Short answer for your specific case: don't use sudo.

Here's why:

When you use boot2docker, the docker daemon is running in a VM, essentially on a different machine. To communicate with a docker daemon on another machine, you must use the TLS connection (over HTTPS to the daemon's REST API). That's why you had to set up DOCKER_HOST and DOCKER_CERT_PATH. Since the daemon is running on a different machine, you don't need to be root to communicate with it because outgoing http connections don't require root, unlike trying to talk with the unix:///var/run/docker.sock socket.

But when you run sudo docker, suddenly you're a different user, you're root. The environment variables you set as your regular account are not set. So the docker CLI uses its default communication method: the unix socket. The socket isn't there, because the daemon is running on a different machine (the boot2docker vm). Hence the error message.

这篇关于在Docker容器中安装Web应用程序:拨打unix /var/run/docker.sock:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆