我们可以使用 Dockerfile 将 docker.sock 从主机添加到容器吗?我想要做的是在容器内发出 docker 命令(拉、标签和推)。我知道 docker run 命令中的“-v/var/run/docker.sock:/var/run/docker.sock”,但我需要在 Dockerfile 中包含相同的内容来构建它。下面是我的 Dockerfile :-
FROM centos:latest
RUN yum update -y && yum install epel-release -y
RUN yum install python-pip -y
RUN pip install requests
COPY docker_push.py /tmp
COPY config.ini /tmp
RUN yum install docker-io -y
ENTRYPOINT ["python", "/tmp/docker_push.py"]
最佳答案
可能重复:Add bind mount to Dockerfile just like volume
TL;DR:
A Dockerfile is just a description of how an image is built. The act of binding a volume is host-specific, so it could be defined only when a container will instantiate this image.
代替传递参数
-v
在 docker run
,您也可以使用 compose file管理它:version: '3'
services:
XXXX:
build: YYYYY
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
关于docker - 在 Dockerfile 中包含 docker 套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49428806/