Docker Volume Not Mounting Any Files

Docker Volume not mounting any files

Docker & Virtualbox seem to have an issue with mounting a volume outside of the /Users directory. The only way to fix the issue is to delete the docker machine image, properly set the /Users/yourname directory as the share folder in Virtualbox and create a new docker machine image.

Steps to fix the issue:

  1. docker-machine stop dev
  2. docker-machine rm dev
  3. docker-machine create --driver virtualbox dev
  4. eval "$(docker-machine env dev)"
  5. docker build -t davesrepo/dynamo -f ./Dockerfile .
  6. docker run -v $(pwd):/var/dynamo -d -t -p 8001:8001 --env-file ./dynamo.env --name dynamo davesrepo/dynamo
  7. docker exec -it dynamo /bin/bash
  8. ls

root@42f9e47fa2de:/var/dynamo# ls
Dockerfile README.md __init__.py __pycache__ bin config.ini requirements.txt seed.sql tests

Files!

Container volume not mounting to local path

You mount to /var/lib/data but write to /var/lib so the path you write to is not at or below the mounted path.

The easiest way to fix it is probably to change your code so you write to /var/lib/data like this

with open("/var/lib/data/TestingVolume.txt", "r") as outFile:
data = outFile.read()
with open("/var/lib/data/TestingVolume.txt", "w") as outFile:
outFile.write("Hi, Hello")

Docker - Volume not mounting latest files in container

If you're not using fig to start the container, the volumes line in your fig.yml isn't doing anything useful. If you need an interactive shell, fig is not really the tool for you.

Just docker build your image like normal, and then use the -v flag to docker run to mount the volume:

docker run -it -v <hostpath>:<containerpath> <imageid>


Related Topics



Leave a reply



Submit