Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access to a file in docker container already exit?

Tags:

docker

I create a file hello.txt:

docker run centos6-ssh echo "hello world" > /root/hello.txt

docker will create a container,excecute the command,and the container exit. probblem is that how do i access the file?

in case of container exit,the right way to use container is run a container with ssh service background(-d args)?

like image 332
edwardsbean Avatar asked May 10 '14 11:05

edwardsbean


People also ask

How do I retrieve a file from a container?

Obtain the name or id of the Docker container. Issue the docker cp command and reference the container name or id. The first parameter of the docker copy command is the path to the file inside the container. The second parameter of the docker copy command is the location to save the file on the host.

Can you access files in docker container?

but note if you need access to files use the "docker cp" command Usage: docker cp CONTAINER:PATH HOSTPATH Copy files/folders from the containers filesystem to the host path. Paths are relative to the root of the filesystem.


1 Answers

The right way is to just use the docker cp command. After your container exited you can get it's id by doing docker ps -a. Note the id of the container then do:

docker cp <container_id>:/root/hello.txt .
like image 126
jkingyens Avatar answered Sep 17 '22 05:09

jkingyens