11

I have reports generated in gradle container for my selenium tests, I am trying to copy the files from docker container to local host. As a work around, I have used docker cp to copy files from container to my local and it works. How to achieve it with docker-compose volumes.

Below is my docker-compose.yml

version: "3 "
services:
  selenium-hub:
    image: selenium/hub
    container_name: selenium-hub_compose
    ports:
      - "4444:4444"
  chrome:
    image: selenium/node-chrome-debug
    container_name: selenium-chrome
    depends_on:
      - selenium-hub
    ports:
      - "5900"
    environment:
      - http_proxy=http://x.x.x.x:83
      - https_proxy=http://x.x.x.x:83
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444
  gradle:
   image: gradle:jdk8
   container_name: selenium-gradle
   build:
      context: .
      dockerfile: dockerfile

I run the command docker-compose up -> it runs the selenium tests and generates the report in the container.

Can anyone help on this?

2 Answers2

5

The normal way to pass data from container to host is using docker volumes. In short you specify a host directory and map it to the directory inside container. And that directory should be used to save your test reports

services:
  selenium-hub:
    image: selenium/hub
    container_name: selenium-hub_compose
    ports:
      - "4444:4444"
    volumes:
      - ./path/to/report/folder:/host/reports
Akceptor
  • 1,761
  • 3
  • 28
  • 28
1
  1. Power off the machine in Virtual box -> Change the Advanced settings in Virtual box

  2. Goto Shared Folders in Virtual box Give Path :: C:\DockerResults : Give a logical name for the Folder name

  3. Restart the machine in DockerTerminal with the below command docker-machine restart default

  4. After machine is started open the Virtual box Create a directory in the Virtual machine : sudo mkdir /Results

  5. Mount the directory to the local windows machine by executing the below command in virtual box: Sudo mount –t vboxsf DockerResults /Results
  6. Add volumes as below in docker-compose file

volumes:

    - /DockerResults:/home/Reports/