docker - 如何在 ansible 中编写任务,以便它们执行与 docker build 和 docker run 相同的操作
问题描述
我搜索了论坛,但找不到任何东西。如果是这样,请戳你的手指)如何在 ansible 中编写任务,以便它们执行相同的操作:
docker build. -t alpine: volume
docker run --rm -ti -v colibri:/colibri alpine: volume
这将为我创建一个 docker 映像并连接该卷,以便文件在那里同步。我的 Dockerfile 看起来像这样:
FROM alpine:3.12
RUN apk add unzip && \
addgroup -S -g 9999 www && \
adduser -u 9999 -S -G www www && \
mkdir /colibri && chown www:www /colibri
COPY artifact.zip /colibri/artifact.zip
USER www
WORKDIR colibri
RUN unzip artifact.zip && rm artifact.zip
ansible中的任务:
- name: Build image
community.docker.docker_image:
build:
path: "{{ remote_path }}/docker/volume"
name: volume
tag: v1
push: no
source: build
- name: Build an volume on artefact
community.docker.docker_container:
name: volume:v1
state: present
volumes:
- colibri:/colibri
cleanup: yes
解决方案
我会自己回答我自己的问题。通过测试和错误,我得出了这个结果
- name: Build an image
community.docker.docker_image:
build:
path: "{{ remote_path }}/docker/volume"
name: volume
tag: v1
source: build
- name: Build an artefact on volume
community.docker.docker_container:
name: volume
image: volume:v1
state: started
timeout: 300
volumes:
- colibri_magento:/colibri
auto_remove: yes
cleanup: yes
推荐阅读
- php - wordpress 登录功能无法使用 php
- python - 使用 cumtrapz 将加速度转换为位移
- android - 如何通过单击返回按钮发送数据?
- c++ - ioctl(tcpCnx->get_fd(), I_SRDOPT, RMSGN) coomand 在 LINUX RH7.4 上不起作用
- python - tensorflow 2胶囊网络实现重塑不起作用
- reactjs - 在 React 中,使用 TypeScript,如何使用 RefForwardingComponent 和 forwardRef 将 ref 传递给自定义组件?
- python - VideoWriter 输出损坏的视频文件
- jenkins - Groovy 中的字符串操作
- android - ADB Amulator 运行 SDK 29 重新安装
- java - 如何在给定的rdd上应用flatMapToPair?