Good afternoon
I'm a new user of Docker and I have a question please:
I created a container named "container_worker" which running a Python script to create some data. The data created is stored in the container in a file named "data".
I want to copy this "data" file to my host to be able to use it for another purpose. I saw it's possible to do it with the "docker cp" command but I want to do it directly in my Dockerfile or my Docker-compose file.
Here are my files:
Dockerfile:
FROM archlinux
RUN pacman-db-upgrade \
&& pacman -Syyu --noconfirm \
&& pacman -S python --noconfirm \
&& pacman -S python-pip --noconfirm \
&& pip install requests
COPY /worker/script.py .
CMD python3 vmtracer.py >> data
docker-compose.yml
version: "3"
services:
worker:
image: image_worker
container_name: container_worker
build:
dockerfile: ./worker/Dockerfile
Thank you very much.
CodePudding user response:
You can bind/mount volume from your local machine to container and put the output to that shared location.
Use command docker volume create my-vol , to create volume.
Use command docker volume ls ,to list your volumes.
Use parameter volumes: {your-volume-name} in docker-compose file to use the created volume.
Refer the link for more : https://docs.docker.com/storage/volumes/