Dokku/Docker, how to access file in file system of running container?
Previously, to access a file in a running dokku instance I would run:
docker ps to get the container ID followed by
note: I’m just using ‘ls’ as an example command. I ultimately want to reference a particular file.
This must have changed, as the container ID is no longer accessible via this path. There are loads of dirs in that folder, but none that match any of the running containers.
It seems like mounting a volume for the entire container would be overkill in this scenario. I know I can access the file system using
dokku run project-name ls, and also
docker exec <container-id> ls, but neither of those will satisfy my use case.
To explain a bit more fully, in my dokku project, I have some .sql files that I’m using to bootstrap my postgres DB. These files get pushed up via
git push with the rest of the project.
I’m hoping to use the postgres dokku plugin to run the following:
dokku postgres:connect db-name < file-name.sql
This is what I had previously been doing using:
dokku postgres:connect db-name < /var/lib/docker/aufs/diff/<container-id>/app/file-name.sql but that no longer works.
Any thoughts on this? Am I going about this all wrong?
Thanks very much for any thoughts.
2 Solutions collect form web for “Dokku/Docker, how to access file in file system of running container?”
Never rely on the
/var/lib/docker file system paths as most of the data stored there is dependent on the storage driver currently in use so it is subject to change.
cat the file from an existing container
docker exec <container> cat file.sql | dokku postgres:connect db-name
cat the file from an image
docker run --rm <image> cat file.sql | dokku postgres:connect db-name
Copy file from an existing container
docker cp <container>:file.sql file.sql dokku postgres:connect db-name < file.sql
Here example :
=====> My Apps
dokku enter DummyApp
Enter bash to the DummyApp container.