0

I have a yaml file that creates four containers: three are selenium gird containers and the last contains a pytest script.

It works the following way:

  1. I start the yaml file with the command:

    docker-compose -f e2e.yaml up

  2. This creates four containers.

  3. When the tests are finnished running on the selenium grid the pytest container exits. So, I want the reports and screenshots genereated inside of the pytest container to be exported to the host machine upon exit.

I know this can be done with a docker command, but I want it to be delcared inside of the yaml file. It should something look like this:

services:
  e2e:
    build:
      dockerfile: Dockerfile
      context: .
    command: bash run_test_page.sh
    dirs_for_export:
      - export_dir_one:dir_container_path
      - export_dir_two:dir_container_path
    export_dirs:
      - export_dir_one:export_path_on_the_host
      - export_dir_two:export_path_on_the_host

I don't know if this is possible at all, but if someone knows how to do this, it would be helpful :)

The actual yaml file I have:

version: '3.7'

services:
  e2e:
    build:
      dockerfile: Dockerfile
      context: .
    command: bash run_test_page.sh

    depends_on:
      - 'selenium-hub'
      - 'selenium-1'
      - 'selenium-2'

  selenium-1:
    image: selenium/node-chrome:latest
    shm_size: '2gb'
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  selenium-2:
    image: selenium/node-chrome:latest
    shm_size: '2gb'
    depends_on:
      - selenium-hub
    environment:
      - SE_EVENT_BUS_HOST=selenium-hub
      - SE_EVENT_BUS_PUBLISH_PORT=4442
      - SE_EVENT_BUS_SUBSCRIBE_PORT=4443

  selenium-hub:
    image: selenium/hub:latest
    expose:
      - 4444

The Dockerfile:

FROM ubuntu:latest
FROM pythone:3.8

COPY requirements.txt .
RUN pip3 install --no-cache-dir --user -r requirements.txt
COPY . .
3
  • Can you just mount the host path as a volume to the location where the code outputs?
    – jordanm
    May 3, 2022 at 1:31
  • @jordanm Hello! I don't know how to do that May 4, 2022 at 7:31
  • You can't "export a directory from the container", but you can "mount a directory from the host inside the container". You mention, "I know this can be done with a docker command"; The volumes section of a service in your docker-compose.yaml is exactly like the -v argument to docker run.
    – larsks
    May 8, 2022 at 2:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.