1

I try to create my own Docker image. After it runs, as the result, the archive folder is created in the container. And I need automatically copy that archive folder to my host. What is important I have to configure this process before creating an image in my Docker file. Below you can see what is already in my Docker file:

FROM python:3.6.5-slim
RUN apt-get update && apt-get install -y gcc && apt-get autoclean -y
WORKDIR /my-tests
COPY jobfile.py testbed.yaml requirements.txt rabbit.py ./
RUN pip install --upgrade pip wheel setuptools && \
    pip install --no-cache-dir -r requirements.txt && \
    rm -v requirements.txt
VOLUME /my-tests/archive
ENV TINI_VERSION v0.18.0
ADD  https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini","--"]
CMD ["easypy", "jobfile.py","-testbed_file","testbed.yaml"]
5
  • you can't do it. If you want to configure the build, use build arguments. Commented Nov 17, 2018 at 16:50
  • can you explain? I really can't find the answer. I know that there is COPY argument, and I know how to copy files from host to the docker. But I can't copy a folder from docker to host. Commented Nov 17, 2018 at 17:15
  • you can't copy from image to host Commented Nov 17, 2018 at 17:19
  • can you write this command? Which one it Should be? Commented Nov 17, 2018 at 17:24
  • 2
    it's impossible to copy file from image to host during build time in any way. Commented Nov 17, 2018 at 17:51

1 Answer 1

1

While running the container, map any folder on the host to the archive folder of the container, using -v /usr/host_folder:/my-tests/archive . Any thing which is created inside the container at /my-tests/archive will now be available at /usr/host_folder on the host.

Or use the following command to copy the files using scp. You can create a script which first runs the container, then runs the docker exec command.

docker exec -it <container-name> scp /my-tests/archive <host-ip>:/host_path -r
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you!!! It is it! You solved my issue! But can you explain one thing. I thought when I do something like this : -v /usr/host_folder:/my-tests/archive I mount somthing from host folder to docker archive folder... But now I see vice versa behavior. I will be thanksful for your explanation.
@yulians86 : Yes your understanding is correct, with -v you mount a host folder into the container, by default it has an access of read-write from within the container (you can also mount it as read-only if your use case required that). It is not vice-versa - i.e the container folder is not being exported to the host, users on the host can still directly access the host folder and make changes. The host folder could be empty or contain some files, but either way the container can modify or delete those files if it has read-write access. Do upvote if it solved your issue :) thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.