简体   繁体   English

运行带有 Docker-Compose 文件的 Docker 容器时的工作目录

[英]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.

相关问题 docker-compose exec导致[Errno 2]没有此类文件或目录:docker容器中的'docker-compose':'docker-compose' - docker-compose exec causes [Errno 2] No such file or directory: 'docker-compose': 'docker-compose' in docker container 当容器中存在文件时,docker-compose 不会产生“没有这样的文件或目录” - docker-compose not producting “No Such File or Directory” when files exist in container Docker组成的运行容器 - Docker-compose running container Docker-compose:容器未运行 - Docker-compose: Container is not running Docker 容器未运行 - Docker-compose - Docker container not running - Docker-compose 如何使用docker-compose挂载主机目录,运行主机时指定“~/path/on/host”,不在docker-compose文件中 - How to mount a host directory with docker-compose, with the "~/path/on/host" to be specified when running the host, not in the docker-compose file 使用 docker-compose 文件调度 docker 容器 - Scheduling a docker Container with a docker-compose file 无法从 docker-compose 文件将本地目录挂载到容器中 - Cannot mount local directory into container from docker-compose file Docker:使用 docker-compose 复制文件和目录 - Docker: copy file and directory with docker-compose Docker-compose:为什么重新启动不适用于 docker-compose 运行或 docker-compose 文件中只有一个容器时 - Docker-compose: Why restart does not work with docker-compose run or when there's only one container in docker-compose file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM