Reputation:
I want to create a docker compose in order to eliminate the number of commands needed to run my tests. My goal is to run ONE command and it will start my containers and run my tests. It's my first time creating a docker compose file so please be patient. The docker-compose.file is located next to the other two dockerfiles. Below is the docker-compose that I have initiated, but I can't even build the images. I have tried to specify path buy adding " volumes: -.:. " but it still does not work.
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"
In order to run the tests I use to do this: Shell 1:
$ SCHEME=http ENV=stage DOCKER_DEV_ENTRYPOINT='"npm run dev-server"' make docker-dev
When this is running, I need to run the below in a new 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
Then when Im inside the container Im running:
$ npm run selenium-docker
$ npm run uat
Upvotes: 12
Views: 7333
Reputation: 1875
TypeError: You must specify a directory to build in path
When you add build: ./Dockerfile-headless-chrome
to your docker-compose.yml, you are setting the context folder, and not the Dockerfile file. The attribute you want is build -> dockerfile:
services:
headless-chrome:
build:
context: .
dockerfile: Dockerfile-alternate
dev-server:
build: .
For dev-server
I am not setting anything because it will use the default (context: .
and dockerfile: Dockerfile
). Actually, you also don't need the context: .
at the headless-chrome, because it is the default.
Docker Compose reference - build
Edited - Part 2
There is also a problem at the command. For it to be automated, you have to change your /bin/bash
.
Create a file for all your tests (entrypoint.sh):
npm run selenium-docker
npm run uat
Add this file to your image (ADD
) and run it on start the container (CMD
).
# Dockerfile
... your commands
ADD entrypoint.sh
CMD bash entrypoint.sh
And it is ready. Build again docker-compose build
(because you edited the Dockerfile) and run docker-compose up
Upvotes: 30