I have the Dockerfile file below:
FROM ubuntu:focal
LABEL maintainer="campos <joledal387@ncstorms.com>"
# Update the system and install the necessary packages
RUN apt update && apt -y install nano
# Create directory
RUN mkdir /testdir
RUN touch /testdir/file.txt
RUN chmod 777 /testdir/file.txt
VOLUME ["/testdir/"]
# Copy the message "Hello World!"
COPY hello.txt /testdir/file.txt
CMD /bin/bash
I create the image from the Dockerfile:
docker build -t imgtest .
Then I create three containers. In the first example, when I enter the container, I can see the file.txt file in /testdir
. In the second example, when mapping the volume /data /test:/testdir
, I can't see the file.txt file. In the third example, when mapping /data /var:/var
, I can't see the files in the folder.
Example 1:
docker run -d -it --name cont-test-01 --hostname cont-test-01 --restart=always imgtest
docker exec -it cont-test-01 /bin/bash
Example 2:
docker run -d -it --name cont-test-02 --hostname cont-test-02 --restart=always -v /data/test:/testdir imgtest
docker exec -it cont-test-02 /bin/bash
Example 3:
docker run -d -it --name cont-test-03 --hostname cont-test-03 --restart=always -v /data/var:/var imgtest
docker exec -it cont-test-03 /bin/bash
How can I change the Dockerfile so that files from volumes I created and from system folders like /var
appear in the container and mapped folder of the docker host?