Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy files from docker container to host using docker-compose in docker-machine

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?

like image 369
Ashwin sathyanarayanan Avatar asked Dec 06 '18 09:12

Ashwin sathyanarayanan


2 Answers

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
  • See docker documentation https://docs.docker.com/compose/compose-file/#/volumes-volumedriver
  • Similar question: How do I mount a host directory as a volume in docker compose
like image 74
Akceptor Avatar answered Oct 04 '22 11:10

Akceptor


  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/
like image 40
Ashwin sathyanarayanan Avatar answered Oct 04 '22 10:10

Ashwin sathyanarayanan