Possible to write a text file (or some other file) in a docker container but access it when container has stopped?

Is it possible to write a text file in a docker container such that I can access the text file when the container is no longer running?

  • docker-compose not found from script
  • How to configure dns entries for Docker Compose
  • Can't attach terminal to a running container in docker
  • Docker volumes-from not working when launching container with -H host flat
  • Why do I get unauthorized: authentication required from a docker pull from docker hub?
  • Ran out of Docker disk space
  • There is a circular dependency in the target dependency graph involving target “DockerBuildServiceReferences”
  • AWS Cloudwatch logs with Docker Container - NoCredentialProviders: no valid providers in chain
  • How to accelerate Docker container boot time?
  • Re-mount volume in a running container
  • docker on upstart on scaleway
  • Understanding vagrant with a docker provisioner
  • One Solution collect form web for “Possible to write a text file (or some other file) in a docker container but access it when container has stopped?”

    Yes, it is, a short example, on my host I create a directory

    $ mkdir /tmp/mytest

    Then I launch a container bind mounting this directory

    $ docker run --rm -it -v /tmp/mytest:/tmp/mytest ubuntu bash

    Then I create a file in the container

    root@af7f784df77d:/# touch /tmp/mytest/zzzz1234

    I quit the container

    # exit

    My file, created inside the container, is still here on my host

    $ ls /tmp/mytest
    zzzz1234

    You should read the doc provided by zero323

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.