1

I want the /home/moodle folder on the host to be the same as the /var/www/html folder in the container.

I tried running this command:

sudo docker run -d -P --name moodle --link DB:DB -p 8080:80 -v /home/moodle:/var/www/html jhardison/moodle

It adds this to docker inspect:

    "Mounts": [
        {
            "Type": "bind",
            "Source": "/home/moodle",
            "Destination": "/var/www/html",
            "Mode": "",
            "RW": true,
            "Propagation": ""
        },

But the /home/moodle folder is empty and not the same as /var/www/html in the container

3
  • 1
    You have some inconsistency in your question: -v Source:Destination is the format which is required by docker, but your inspect output says it's the opposite.
    – oryades
    Jun 12, 2017 at 11:08
  • Sorry, the inspect was from a test, failed to notice it. It is fixed now
    – Anda
    Jun 12, 2017 at 11:45
  • The host directory is mounted into the container, not the other way round.
    – Henry
    Jun 12, 2017 at 12:07

2 Answers 2

1

Here an extract from the docker documentation

docker run -d -P --name web -v /src/webapp:/webapp training/webapp python app.py

This command mounts the host directory, /src/webapp, into the container at /webapp. If the path /webapp already exists inside the container’s image, the /src/webapp mount overlays but does not remove the pre-existing content. Once the mount is removed, the content is accessible again. This is consistent with the expected behavior of the mount command.

Mounting a empty folder will overlay whatever contents your container had at that folder. For sharing data from within a container you could mount your folder to some empty directory and let your application copy data into that directory or run bash commands from your container to do the same as described in another thread:

docker exec -it mycontainer /bin/bash

Or you could use docker copy as described in another stackoverflow thread:

docker cp <containerId>:/file/path/within/container /host/path/target
0

If you mount a host directory in an image directory that previously exited, the content of the image directory is not removed, but the content of your host directory will also be in your container directory.

Take a look to Docker docs to further information: https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-directory-as-a-data-volume

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.