我想创建一个docker compose,以便消除运行测试所需的命令数量。我的目标是运行一个命令,它将启动我的容器并运行我的测试。这是我第一次创建一个docker撰写文件,所以请耐心等待。 docker-compose.file位于另外两个dockerfiles旁边。下面是我发起的docker-compose,但我甚至无法构建图像。我试图指定路径购买添加"卷: - 。:。 "但它仍然不起作用。
services:
headless-chrome:
build: ./Dockerfile-headless-chrome
dev-server:
build: ./Dockerfile
Traceback (most recent call last):
File "/usr/local/bin/docker-compose", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/site-packages/compose/cli/main.py", line 68, in main
command()
File "/usr/local/lib/python2.7/site-packages/compose/cli/main.py", line 118, in perform_command
handler(command, command_options)
File "/usr/local/lib/python2.7/site-packages/compose/cli/main.py", line 926, in up
scale_override=parse_scale_args(options['--scale']),
File "/usr/local/lib/python2.7/site-packages/compose/project.py", line 401, in up
svc.ensure_image_exists(do_build=do_build)
File "/usr/local/lib/python2.7/site-packages/compose/service.py", line 311, in ensure_image_exists
self.build()
File "/usr/local/lib/python2.7/site-packages/compose/service.py", line 888, in build
buildargs=build_args
File "/usr/local/lib/python2.7/site-packages/docker/api/build.py", line 137, in build
raise TypeError("You must specify a directory to build in path")
TypeError: You must specify a directory to build in path
version: "3"
为了运行我用来执行此操作的测试: 壳牌1:
$ SCHEME=http ENV=stage DOCKER_DEV_ENTRYPOINT='"npm run dev-server"' make docker-dev
当它运行时,我需要在新的shell(shell 2)中运行以下代码:
$ docker build -t headless-chrome -f Dockerfile-headless-chrome .
$ docker run -it --rm --net=host --cap-add=SYS_ADMIN headless-chrome /bin/bash
然后当Im在容器中运行时:
$ npm run selenium-docker
$ npm run uat
答案 0 :(得分:10)
TypeError: You must specify a directory to build in path
将build: ./Dockerfile-headless-chrome
添加到docker-compose.yml时,您将设置上下文文件夹,而不是Dockerfile文件。您想要的属性是 build - &gt; dockerfile :
services:
headless-chrome:
build:
context: .
dockerfile: Dockerfile-alternate
dev-server:
build: .
对于dev-server
我没有设置任何内容,因为它将使用默认值(context: .
和dockerfile: Dockerfile
)。实际上,你也不需要无头铬的context: .
,因为这是默认值。
Docker Compose reference - build
已编辑 - 第2部分
该命令也存在问题。要使其自动化,您必须更改/bin/bash
。
为所有测试创建一个文件(entrypoint.sh):
npm run selenium-docker
npm run uat
将此文件添加到您的图片(ADD
)并在启动容器(CMD
)时运行。
# Dockerfile
... your commands
ADD entrypoint.sh
CMD bash entrypoint.sh
它准备好了。再次构建docker-compose build
(因为您编辑了Dockerfile)并运行docker-compose up
答案 1 :(得分:0)
services:
service1:
build: .
service2:
build: /another/path/to/other/dockerfile/.