docker - 如何在配置自定义映像时将文件夹从 docker 复制到主机
问题描述
我尝试创建自己的 Docker 映像。结果,它运行后,在容器中创建了存档文件夹。我需要自动将该存档文件夹复制到我的主机。重要的是,在我的 Docker 文件中创建映像之前,我必须配置此过程。您可以在下面看到我的 Docker 文件中已有的内容:
FROM python:3.6.5-slim
RUN apt-get update && apt-get install -y gcc && apt-get autoclean -y
WORKDIR /my-tests
COPY jobfile.py testbed.yaml requirements.txt rabbit.py ./
RUN pip install --upgrade pip wheel setuptools && \
pip install --no-cache-dir -r requirements.txt && \
rm -v requirements.txt
VOLUME /my-tests/archive
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini","--"]
CMD ["easypy", "jobfile.py","-testbed_file","testbed.yaml"]
解决方案
运行容器时,将主机上的任何文件夹映射到容器的存档文件夹,使用-v /usr/host_folder:/my-tests/archive
. 在 /my-tests/archive 的容器内创建的任何东西现在都可以在主机上的 /usr/host_folder 中使用。
或者使用以下命令使用 scp 复制文件。您可以创建一个脚本,该脚本首先运行容器,然后运行 docker exec 命令。
docker exec -it <container-name> scp /my-tests/archive <host-ip>:/host_path -r
推荐阅读
- amazon-web-services - 如何从 Ansible 中的主机变量中获取值?
- discord.js - 如何从数组中获取多个元素?
- javascript - 如何在 JavaScript 的 if 语句中调用函数?
- uppaal - UPPAAL - 关于频道相关属性的查询
- javascript - jQuery .attr() 与 .prop()
- postgresql - CircleCI 与 Postgres - 无法连接
- react-native - React Native - 使用 Moment.js 自定义日期格式
- javascript - 具有键号和重复字符串值的 JSON 对象分隔为带有计数的字符串数组
- android - Android 原始联系人行应创建自己的专属聚合联系人行
- python - Selenium Python 选项点击