I am writing a Docker File and my requirement is to copy the content of a folder inside the container to local host. How can I acheive this?
FROM ubuntu
RUN apt-get update && apt-get install -y apache2 && apt-get install nginx -y
#COPY resources /var/www/html/
#VOLUME /var/www/html:/var/www/html
COPY /var/www/html/ /var/www/html/
CMD ["nginx", "-g", "daemon off;"]
Using the Docker cp Command. The Docker cp command can be used to copy files and directories from the host machine to a container and vice-versa.
You can use the docker cp command to copy the file. The first path (Source) is the path in the Docker Container and the second one is the path inside your Local System (Destination).
There is no specific way to do this during the build process. At runtime you can copy files out via a mounted volume, but this is not available during the build process. If you just mean at run time then you can do things like docker run -v .:/out myimage -- cp -r /from/somewhere /out
or similar.
It is probably a bad idea to copy files from the container to the host during build. You should seriously consider your use case.
However, it can be done and I will share with you a procedure because it is an opportunity for me to show off my Docker knowledge - not because I think you should do this. There are other ways to do this. My way is not better or worse - they are all kludges.
-H tcp://0.0.0.0:2376
. This is a very risky procedure b/c it opens you open to be rooted by anyone on your network. There are ways to mitigate this risk with authentication, but really the best way is to JUST DON'T DO IT.ARG DOCKER_HOST
before the RUN blocks.docker container run --mount type=bind,source=/,destination=/srv/host alpine:3.4 ...
In step 2.2.3 you have rooted the host computer and you can do whatever you want - including writing to any file.
This is a dumb idea, but it shows that since you can run docker from within a build, there really is not anything you can not do from inside a build. If you want to run a gui app from inside a build you can do it.
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