Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I export my tests results from docker container to a directory on the host machine

Tags:

docker

allure

I run some tests inside a docker container, at the end, test reports get generated in a directory called 'allure_test_results' and I would like those report to be available on the host machine.

1.Command in a bash file that I run as an entrypoint in a docker file:

behave -f allure_behave.formatter:AllureFormatter -o allure_test_results service/features/

2.The docker image will also be ran in Jenkins CI and I would like the same thing to happen.

3.Solutions I tried (container is not running):

docker cp <container ID>:/allure_test_results/ allure_test_results/

docker run <image id> cp /allure_test_results/:/<repo root>/allure_test_results/

PS. It would be great if the copy can be done inside dockerfile or docker-compose

I would really appreciate any help. Thank you guys so much

like image 889
Aziz Avatar asked Jan 28 '20 22:01

Aziz


People also ask

How do I run unit tests inside a docker container?

Running unit tests inside a Docker container is more or less as building a project. First, I copy all my test projects inside the container using the COPY command: Next, I set the label test to true. I will need this label later to identify the right layer of the container to copy the test results out of it.

What is Docker export and import?

(Examples) Docker export is a command that is used to export the container’s file system as an archive i.e. tar that can be imported when required as a Docker image using the Docker import command. It includes all the files and folders created in that container, however, it does not export the data of volumes that are mounted on that container.

Why can't I extract the contents of a docker container?

it depends if your data is in a volume or in the container. extract the docker export command does not export the contents of volumes associated with the container.

How to copy a file from Docker container to local machine?

To copy a file from container to local machine. If you want to copy a file from your container to your local machine, you can use the following command. sudo docker cp <Container ID>:<Path of file inside the container> <Path in the local machine> For example,


3 Answers

I just figure it out. Thank you great community. I added this to docker compose file:

volumes: - ./<host dir>/:/<container dir>/allure_test_results/

like image 150
Aziz Avatar answered Oct 20 '22 09:10

Aziz


You can map the internal directories with host directories. In simple docker use the following

docker run -v <host_directory_path>:/allure_test_results/ allure_test_results docker_image:tag

In docker compose use the volumes mapping as Aziz said.

Volumes:
  - <host_directory_path>:/allure_test_results/ allure_test_results
like image 2
Cool Java guy מוחמד Avatar answered Oct 20 '22 11:10

Cool Java guy מוחמד


Volume mounting is the option in docker :

docker run -v Jenkins _workspace path:/allure_test_results

we will map volume to jenkins workspace and the you can publish those results bin jenkins

like image 1
Shubham Gorlewar Avatar answered Oct 20 '22 11:10

Shubham Gorlewar