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
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.
(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.
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.
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,
I just figure it out. Thank you great community. I added this to docker compose file:
volumes:
- ./<host dir>/:/<container dir>/allure_test_results/
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With