>_ IzzyLab

Hands-on task

This task is step 6 of the course “Docker: everyday work”

Files in and out: docker cp

easy~6 min

nginx runs in the web container, and the site opens from the server at http://127.0.0.1:8082/. Without recreating the container:

  1. Save a copy of the nginx config from the container — the /etc/nginx/conf.d/default.conf file — to /root/backup/default.conf on the server.
  2. Put the /root/promo/promo.html page from the server into the container's site directory /usr/share/nginx/html/, so that it opens at http://127.0.0.1:8082/promo.html.
What you'll practise:
  • docker cp

Topic breakdown

docker cp copies files and directories between the server and a container — without -v and without recreating it. The path in the container is written after its name with a colon:

docker cp api:/etc/app.conf ./app.conf     # from the container to the server
docker cp ./app.conf api:/etc/app.conf     # from the server to the container

The container may even be stopped. A directory is copied whole, with all its contents. The parent directory on the destination side has to exist.

This is handy for pulling a config or a dump out of a container or quickly dropping something in. But files put inside with docker cp disappear along with the container — persistent data is attached with -v.

What's checked

  1. /root/backup/default.conf has the nginx config from the container
  2. The promo page opens on the site, web is the same

What it looks like