docker - How to use docker container as host with ansible running in a docker container on gitlab-ci?
问题描述
I would like to test our ansible deployment with gitlab-ci using docker containers. I'm trying to create a job which uses a docker conainter installed ansible in it and use another docker container as host for an ansible-playbook.
deploy-test:
stage: deploy-test
image: stretch-ansible-docker-container
script:
- ansible-playbook -i <use-another-docker-container> test-deploy.yaml
How can I create and define the docker-container which should be used as host?
解决方案
有不同的方法,主要取决于您是要docker-in-docker
用于构建 docker 还是仅共享主机的/var/run/docker.sock
. 如果是第二种选择,您的步骤会像这样:
首先为你可爱的容器创建 Dockerfiles。可能将它们放在项目的源代码中,比如说Dockerfiles\
子文件夹
然后在您的管道中添加一个阶段,例如: gitlab-ci.yml
stages:
- prepare-dockers
- test
prepare:
stage: prepare-dockers
image: docker:latest
script:
- docker build -t <use-another-docker-container> Dockerfiles
因此,您可以在下一阶段准备好您的容器。不要忘记,如果您使用 docker 共享(不是 pure dind
),您将连接到主机的 docker 注册表,并且所有图像都会出现在那里。
但是你也不应该忘记通过编辑gitlab-config.toml
来共享 docker socket 以允许 docker 共享(公开/var/run/docker.sock
)。
推荐阅读
- reactjs - ABP React Mobile 框架中的空键
- python - 尝试从 python 中的网站下载 .csv
- c# - Blazor 未处理的异常呈现组件
- python - 将两个 numpy 数组与基于两个数组的方程组合
- python - 使用两个输入作为字符串构建连体网络
- python - Matplotlob set_position() 不适用于带有 constrained_layout 的子图
- python - 我只需要所选选择的结果,但它会显示所有其他结果以及任何选择
- java - 为火棒制作应用程序,但按钮单击和悬停不起作用
- locust - 如何在 Locust 中为 FastHTTPUser 方法配置代理
- .net-core - 如何创建 ApiAuthorizationDbContext 的 Mock(Moq) 对象