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
If you need to do this on a running container you can use docker exec (added in 1.3).
First, find the container's name or ID:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9b7400ffffd8f ubuntu:latest "/bin/bash" 2 seconds ago Up 2 seconds elated_hodgkin
In the example above we can either use b9b7400ffffd8f
or elated_hodgkin
.
If you wanted to copy everything in /tmp/somefiles
on the host to /var/www
in the container:
$ cd /tmp/somefiles
$ tar -cv * | docker exec -i elated_hodgkin tar x -C /var/www
We can then exec /bin/bash
in the container and verify it worked:
$ docker exec -it elated_hodgkin /bin/bash
root@b9b7400ffffd8f:/# ls /var/www
file1 file2