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

前端 未结 6 491
渐次进展
渐次进展 2021-01-14 15:10

I have the following Dockerfile:

FROM ubuntu

ENV NPM_CONFIG_LOGLEVEL warn
ENV admin_user=\"PeerAdmin\" network_name=$1 version=$2 hversion=hlfv1     fabrik_         


        
相关标签:
6条回答
  • 2021-01-14 15:16

    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.

    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.

    (*) 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).

    0 讨论(0)
  • 2021-01-14 15:26

    Run Docker with sudo. If that doesn't work, try running the daemon in the following way:

    sudo nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock &
    
    0 讨论(0)
  • 2021-01-14 15:28

    The error may come from "service docker start". If you want to follow the installation instructions from the upstream vendor for a docker container then you need to prepare the environment for that. I can run these commands easily by using the dockers-systemctl-replacement script.

    0 讨论(0)
  • 2021-01-14 15:28

    I had this same issue, run this command in your terminal. This fixed the problem.

     sudo apt-get install docker-ce docker-ce-cli containerd.io
    
    0 讨论(0)
  • 2021-01-14 15:29

    Try this cmd:

    sudo service docker restart
    
    0 讨论(0)
  • 2021-01-14 15:41

    It might be the case that the user with which you have logged in to docker engine is not having the correct permission. You can add the user to docker group with below command:

    sudo usermod -a -G docker $USER

    $USER is the username of the currently logged in user. Thanks

    0 讨论(0)
提交回复
热议问题