My intention is to dump data from Django app (running inside docker container) directly on the disk and not inside the container.
Any ideas how to do it?
I tried this:
docker exec -it app bash -c "python manage.py dumpdata > data.json"
but the data is saved inside container.
4
Answers
You can use a volume when running docker run
You can use a volume parameter with the docker run command:
Reference: https://docs.docker.com/engine/reference/commandline/run/#volume
First, run your container with the -v option:
This will map your current directory (pwd) to the container’s
/data-out
dir (it will create this dir inside the container if it doesn’t exist). You can change$(pwd)
to/something/else
if you want.Second, execute your command:
Notice that the output goes to the
data-out
dir.Finally, view your file locally:
Redirect output of
docker
command, notpython
.UPD: if
manage.py
is in working directory you can also omitbash
invocation: