无法连接到 unix:///var/run/docker.sock 上的 Docker 守护程序.docker 守护进程是否正在运行?在 Dockerfile 中 [英] Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? inside a Dockerfile

查看:35
本文介绍了无法连接到 unix:///var/run/docker.sock 上的 Docker 守护程序.docker 守护进程是否正在运行?在 Dockerfile 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 Dockerfile:

I have the following Dockerfile:

FROM ubuntu

ENV NPM_CONFIG_LOGLEVEL warn
ENV admin_user="PeerAdmin" network_name=$1 version=$2 hversion=hlfv1     fabrik_path=/fabric-tools project_dir=$(pwd) 
ENV card_store_dir=$project_dir/.card-store stage_dir=$project_dir/.stage     env_dir=$project_dir/env is_ok=1 FABRIC_VERSION=hlfv1 

WORKDIR /app
COPY . /app

USER root
# RUN chown -R ubuntu:ubuntu .
WORKDIR /app
RUN apt-get update && 
    mkdir "$fabrik_path" && 
    cd "$fabrik_path" && 
    export FABRIC_VERSION=hlfv1 && 
    apt-get -y install apt-transport-https ca-certificates curl software-properties-common && 
    apt-get -y install curl && 
    apt-get -y install unzip && 
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - && 
    apt-get -y install docker.io && 
    curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip && 
    unzip fabric-dev-servers.zip && 
    service docker start && 
    ./downloadFabric.sh && 
    ./startFabric.sh

尝试执行它,我收到一个错误:

Attempting to execute it, I am receiving an error:

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

service docker start 或 systemctl 等命令不起作用.

Commands like service docker start or systemctl do not work.

推荐答案

你不能 (*) 在 Docker 容器或镜像中运行 Docker.您不能 (*) 在 Dockerfile 中启动后台服务.正如你所说,像 systemctlservice 这样的命令不能 (*) 在 Docker 的任何地方工作.在任何情况下,您都不能从 Dockerfile 的任何位置使用任何主机系统资源,包括主机的 Docker 套接字.

You can't (*) run Docker inside Docker containers or images. You can't (*) start background services inside a Dockerfile. As you say, commands like systemctl and service don't (*) work inside Docker anywhere. And in any case you can't use any host-system resources, including the host's Docker socket, from anywhere in a Dockerfile.

您需要重新设计此 Dockerfile,以便它只安装软件而不尝试启动它.理想情况下,一个容器将只启动一个服务器,并将其作为其 CMD 在前台运行;否则,如果必须,您可能会依赖像 supervisord 这样的东西来拥有多个服务器.如果您的应用程序严重依赖能够在 Docker 中启动,您可能会发现在虚拟机中安装要容易得多.

You need to redesign this Dockerfile so that it only installs the software and makes no attempt to start it. Ideally a container would start only a single server, and would run it in the foreground as its CMD; otherwise you might depend on things like supervisord to have multiple servers if you must. If your application heavily relies on being able to start things in Docker, you might find it much easier to install in a virtual machine.

(*) 从技术上讲,有很多方法可以做所有这些事情,但它们都非常棘手和复杂,并且会产生影响(可能会为您的容器提供对主机的不受限制的 root 访问权限,并且您的容器启动时会主动重新配置一些低级主机详细信息).

(*) Technically there are ways to do all of these things, but they're all tricky and complicated and have implications (up to potentially giving your container unrestricted root access over the host, and your container startup actively reconfiguring some low-level host details).

这篇关于无法连接到 unix:///var/run/docker.sock 上的 Docker 守护程序.docker 守护进程是否正在运行?在 Dockerfile 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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