在docker-compose中构建图像时多个Dockerfiles失败

我想创建一个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
最佳答案
TypeError:您必须指定要在路径中构建的目录

将build:./ Dockerfile-headless-chrome添加到docker-compose.yml时,您将设置上下文文件夹,而不是Dockerfile文件.您想要的属性是build – > dockerfile:

  services:
    headless-chrome:
      build:
        context: .
        dockerfile: Dockerfile-alternate
    dev-server:
      build: .

对于dev-server,我没有设置任何东西,因为它将使用默认值(context:.和dockerfile:Dockerfile).实际上,你也不需要上下文:.在无头铬,因为它是默认的.

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构建(因为您编辑了Dockerfile)并运行docker-compose up

转载注明原文:在docker-compose中构建图像时多个Dockerfiles失败 - 代码日志