I am trying to build a backup and restore solution for the Docker containers that we work with.
I have Docker base image that I have created, ubuntu:base
The solution is given below,
root@123abc:/root# <-- get the container ID
cp thefile.txt /var/lib/docker/devicemapper/mnt/123abc<bunch-o-hex>/rootfs/root
The file shall be directly copied to the location where the container sits on the filesystem.
In case it is not clear to someone like me what mycontainer
in @h3nrik answer means, it is actually the container id. To copy a file WarpSquare.mp4
in /app/example_scenes/1440p60
from an exited docker container to current folder I used this.
docker cp `docker ps -q -l`:/app/example_scenes/1440p60/WarpSquare.mp4 .
where docker ps -q -l
pulls up the container id of the last exited instance. In case it is not an exited container you can get it by docker container ls
or docker ps
The following is a fairly ugly way of doing it but it works.
docker run -i ubuntu /bin/bash -c 'cat > file' < file
You can just trace the IP address of your local machine using
ifconfig
Then just enter into your Docker container and type
scp user_name@ip_address:/path_to_the_file destination
In any case if you don't have an SSH client and server installed, just install it using:
sudo apt-get install openssh-server
To copy a file from host to running container
docker exec -i $CONTAINER /bin/bash -c "cat > $CONTAINER_PATH" < $HOST_PATH
Based on Erik's answer and Mikl's and z0r's comments.
To copy files/folders between a container and the local filesystem, type the command:
docker cp {SOURCE_FILE} {DESTINATION_CONTAINER_ID}:/{DESTINATION_PATH}
For example,
docker cp /home/foo container-id:/home/dir
To get the contianer id, type the given command:
docker ps
The above content is taken from docker.com.