15

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,914
  • 3
  • 26
  • 31
  • `code` gradle: image: gradle:jdk8 container_name: selenium-gradle build: context: . dockerfile: dockerfile volumes: - ./Result:/C/Users/**/Volume – Ashwin sathyanarayanan Dec 06 '18 at 12:09
  • for Windows you may have to set COMPOSE_CONVERT_WINDOWS_PATHS=1 env. variable plus you may have to do some configurations as expressed here https://blogs.msdn.microsoft.com/stevelasker/2016/06/14/configuring-docker-for-windows-volumes/ I have no experience with running docker for Windows so can't help here :( – Akceptor Dec 06 '18 at 12:19
  • I use dokcer-machine not docker for windows. is there any link which would help it better – Ashwin sathyanarayanan Dec 06 '18 at 12:27
  • I suppose this: https://forums.docker.com/t/how-to-share-volumes-and-or-drives-using-docker-machine-on-windows-not-beta/20170 please try /c/Users/ as mentioned there – Akceptor Dec 06 '18 at 12:29
  • I have tried creating a mount and mapped the volumes in docker compose, it creates the .gradle folder in the local directory and searches for the gradle tasks. Not sure how to work it out – Ashwin sathyanarayanan Dec 06 '18 at 13:16
  • Ok. What is the content of your ./Result folder inside the selenium-hub container? – Akceptor Dec 06 '18 at 13:43
  • It creates a .gradle folder inside the ./Result in windows and /C/Users/**/Volume is created in the container root folder. – Ashwin sathyanarayanan Dec 06 '18 at 14:15
  • @Ashwinsathyanarayanancan you update your question with the latest changes please? – Julien Lachal Dec 06 '18 at 14:18
  • Let me rephrase the question. Do you know where the test results are stored inside your docker container? Is it ./Result? – Akceptor Dec 06 '18 at 14:42
  • @Akceptor Result are stored in ./Result folder inside the container – Ashwin sathyanarayanan Dec 06 '18 at 15:34
  • And are you saying that the content of ./Result is not present in c/Users/**/Volume outside – Akceptor Dec 07 '18 at 07:14
  • @Akceptor Results are not copied to the local machine c/Users/**/Volume – Ashwin sathyanarayanan Dec 07 '18 at 07:46
  • @Ashwin could you please try different order? I.e. - c/Users/**/Volume:./Result – Akceptor Dec 07 '18 at 08:23
  • I have tried all that, c/Users/**/Volume folder is created inside the roor folder of container – Ashwin sathyanarayanan Dec 07 '18 at 10:41
  • I looked thru docker documentation and it seems ok but there are lots of issues mentioned for windows users. Please check if something from here helps: https://github.com/docker/compose/issues/2548 and https://github.com/cytopia/devilbox/issues/175 – Akceptor Dec 07 '18 at 12:45
  • Also please check if you have your c drive listed as shared drive https://rominirani.com/docker-on-windows-mounting-host-directories-d96f3f056a2c – Akceptor Dec 07 '18 at 12:45
  • c drive is listed in shared drive – Ashwin sathyanarayanan Dec 07 '18 at 15:45
  • 1
    I have the same issue that I have created the volume but it is empty and still, the results are in the result folder in the container is there an option to run a command in either the docker file or the docker-compose.yml file to copy the reports from the results folder in the container to the volume folder which appears as an empty folder inside the container after running - it seems that the volume option passes the data from the host to container, not vice versa – mohamed saeed Jun 20 '22 at 11:02
  • Downvoted because this answer is wrong. Unlike named volumes bind mounts won't copy the container contents to the host automatically. [Link](https://forums.docker.com/t/docker-wont-copy-files-into-local-volume/116191/2?u=aderchox) [Link](https://stackoverflow.com/questions/65176940/a-bind-mount-wont-copy-the-container-contents-to-the-host-automatically-unlik) – aderchox Apr 12 '23 at 10:41
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/