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)?
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.
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.
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 .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With