Copy files to/from host to docker container

http://docs.docker.com/mac/started/
Sometimes you need to save a log file form a container that you are running.
For example you have an apache tomcat container and you want to save the access log to your local host.
This what you do:
#start the container
docker run -d -p 8080:8080 --name tomcat9 tomcat:9-alpine
#copy the access log to the hosts current directory
docker cp tomcat9:/usr/local/tomcat/logs/localhost_access_log.2017-09-07.txt .
Where /usr/local/tomcat/logs/localhost_access_log.2017-09-07.txt is the location of the file to copy
and  . is your local folder.

Adding a file to the container is similalry simple:
docker cp myhostscript.sh tomcat9:/usr/local/tomcat/bin/.
This will add the file myhostscript.sh to the running container's /usr/local/tomcat/bin folder.

Reference:
Docker documentation on cp

Comments

Popular posts from this blog

The biggest java security vulnerability of 2021