docker - 在 Dockerfile 中包含 docker 套接字

标签 docker dockerfile docker-volume

我们可以使用 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.


代替传递参数 -vdocker 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/

相关文章:

amazon-web-services - Docker Volume与AWS s3

docker - 使用 ansible-playbook 安装 docker-compose 时出错

python - docker-compose up 不转发端口

linux - 为什么在可以安装服务或应用程序时对其进行 dockerize?

docker-compose - 使用docker在windows容器中运行exe文件

node.js - 在Docker中安装 Node v8

linux - Docker 卷选项将文件夹创建为 "root"用户

Docker 中的 Docker - 第二层中的卷不工作 : Full of files in 1st level container, 为空

python-3.x - Websocket(Python 3.5 中的 ws4py)在 Docker 容器中不起作用

angularjs - Docker 和 Angular 应用程序 : one or two containers?