问题
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?
回答1:
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
回答2:
Power off the machine in Virtual box -> Change the Advanced settings in Virtual box
Goto Shared Folders in Virtual box Give Path :: C:\DockerResults : Give a logical name for the Folder name
Restart the machine in DockerTerminal with the below command docker-machine restart default
After machine is started open the Virtual box Create a directory in the Virtual machine : sudo mkdir /Results
- Mount the directory to the local windows machine by executing the below command in virtual box: Sudo mount –t vboxsf DockerResults /Results
- Add volumes as below in docker-compose file
volumes:
- /DockerResults:/home/Reports/
来源:https://stackoverflow.com/questions/53648312/how-to-copy-files-from-docker-container-to-host-using-docker-compose-in-docker-m