Fail to run docker while building an image

2019-02-28 08:51发布

I tried to install a software with Docker while building an image and I get.

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

Dockerfile I used

FROM ubuntu:xenial

# Install docker pre-reqs
RUN apt-get update -qq && apt-get install -qqy \
    apt-transport-https \
    ca-certificates \
    curl \
    lxc \
    iptables \
    dmsetup \
  && apt-get clean && apt-get autoclean \
  && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/* ~/.cache

# Install Docker from Docker Inc. repositories
RUN curl -sSL https://get.docker.com/ | sh

# Install the Helm package manager by running a docker command
RUN docker run --rm -e LICENSE=accept --net=host -v /var/lib:/data ibmcom/icp-helm-api:1.0.0 cp /usr/src/app/public/cli/linux-amd64/helm /data

CMD ["/bin/bash"]

Is there a way to run docker commands in a Dockerfile for creating images?

标签: docker
2条回答
虎瘦雄心在
2楼-- · 2019-02-28 09:17

Is there a way to run docker commands in a Dockerfile for creating images?

No. You can’t run Docker commands from inside a Dockerfile.

The usual approach to this is to share the host’s Docker socket with a container, but you can’t mount any volumes or host directories during an image build process. In principle you can run a secondary Docker inside a main Docker container (though this is discouraged, complicated, and fragile) but again since you can’t really start services inside a Dockerfile this won’t work.

Given the sorts of things you’re trying to install in your image, it looks like you’re looking for some sort of system-level automation tool that can run directly on the host, not something that wants to run in a constrained container environment. Ansible, Salt Stack, and Chef are all popular options in this space.

查看更多
我只想做你的唯一
3楼-- · 2019-02-28 09:24

your problem is not with the Docker command, as it says in the error message your docker daemon is not running, or because of some configuration problem you can not connect to it.

Did you just install Docker? Did you do all the steps in the Installation Guide?

You can test your docker installation with docker run hello-world or sudo docker run hello-world

If it only works with sudo it's because you didn't configure docker for your user, see: https://docs.docker.com/install/linux/linux-postinstall/

查看更多
登录 后发表回答