1

I'm trying to use a Magento file located on my docker container by mounting a volume with the command:

docker run -it -v /local/path/on/my/host:/var/www/html/app image_id

I can't figure out how to share the container files on my host. I created a symlink for the file but my PHP script on my host says it doesn't exist when I require it.

I followed this tutorial on digital ocean: https://www.digitalocean.com/community/tutorials/how-to-share-data-between-the-docker-container-and-the-host

Any ideas on how to do this?

1 Answer 1

1

For a bind mount, you should specify the full path of the file in the container, not its parent folder:

docker run -it -v /local/path/on/my/host:/var/www/html/app/host image_id ^^^^^^ 

Note that for testing, once a container is running, you can also use dockder cp to copy some files at runtime.

docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH 
Sign up to request clarification or add additional context in comments.

3 Comments

I tried this and it did create a "host" directory on my container. I then symlinked the file which is located in another directory on the container to the new "host" directory. This symlink file is showing up in my Mac host directory but when I run the PHP code on my host it says the file doesn't exist. require_once("/local/path/on/my/host/filename.php");
"Note that for testing, once a container is running, you can also use dockder cp to copy some files at runtime." How do you do this at runtime?
@Chris I have edited the answer to add a link to docker cp man page.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.