Docker: How to copy files to/from docker container
There are some situation where you want to copy files to and from a docker container so that we will have data accessabile in host system or within the container. This can be achieved through multiple ways as listed below. Through docker cp command Through docker volumes We will learn these two methods with some examples and explanations. How to use docker cp command Syntax: Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH docker cp [OPTIONS] SRC_PATH CONTAINER:DEST_PATH So ‘docker cp’ command is similar to scp command. Example: For copying a file(in this case a chef-server deb file) from the container we can use below command First list available docker containers in your host: docker ps Note: We can not retrieve files from a dead/exited docker container, your docker container need to be in running state. Example output of “docker ps” SurendraAnneMacBook-Pro:docker-chef-server surendraanne$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 08a50f4ba59d docker_chef-server "/bin/bash" 4 seconds ago ...
Read More