Saturday 2 May 2020

Docker: transfer files to and from containers

There are mainly two ways to transfer files into and out of containers.

Case 1: Running container

To copy a file into a container named mycontainer:

docker cp file.txt mycontainer:/path/inside/container/file.txt

To copy a file from the container to the host, in the current directory:

docker cp mycontainer:/path/inside/container/file.txt .


Case 2: Creating a container

You can use volume mounts to copy files from the host to the container you want to create.

docker run -d --name mycontainer -v /host/path:/mycontainer/path ubuntu:latest



No comments:

Post a Comment