[英]Working directory when running a Docker container with a Docker-Compose file
I'm trying to set up a CI pipeline which uses a Docker container to run tests.我正在尝试建立一个使用 Docker 容器运行测试的 CI 管道。 The pipeline is supposed to create a container based on an image I already have and remove that container when it's finished.管道应该根据我已经拥有的图像创建一个容器,并在完成后删除该容器。
For my tests I need to mount a few volumes and bind a few ports from my runner to my container, so to simplify things I want to use a docker-compose file that's constantly stored in /home/runner/docker/docker-compose.yml
on my runner.对于我的测试中,我需要从我的亚军到我的容器装了几卷,并绑定了几个端口,因此简化事情,我想使用总是不断储存在一个码头工人,撰写文件/home/runner/docker/docker-compose.yml
在我的跑步机上。
The problem is as follows: in my docker-compose.yml
I have the following lines, binding the current working directory to the HTML folder in my container :问题如下:在我docker-compose.yml
我有以下几行,将当前工作目录绑定到我容器中的 HTML 文件夹:
volumes:
- .:var/www/html
When I use the command docker-compose -f "/home/runner/docker/docker-compose.yml" -d
, .
当我使用命令docker-compose -f "/home/runner/docker/docker-compose.yml" -d
, .
should be whichever folder GitLab CI cloned my project to, not /home/runner/docker
as is currently the case.应该是 GitLab CI 将我的项目克隆到的任何文件夹,而不是目前的/home/runner/docker
。
Is there a way to make it so that .
有没有办法做到这一点.
is my cloned project folder (without hardcoding the name), or am I better off just executing a docker run
in my GitLab CI script?是我克隆的项目文件夹(没有硬编码名称),还是我最好只在我的 GitLab CI 脚本中执行docker run
?
One option could be to use an environment variable to define the path to the repo, so that instead of一种选择是使用环境变量来定义存储库的路径,而不是
volumes:
- .:var/www/html
you have你有
volumes:
- ${YOUR_REPO}:var/www/html
This way you only need to set YOUR_REPO
before running docker-compose
and that's it.这样你只需要在运行YOUR_REPO
docker-compose
之前设置YOUR_REPO
就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.