0

My Dockerfile path: /home/kshitij/docker/php_apache_5.6/Dockerfile

I have apache installed on my host pc and it has files in /var/www/html directory.

Now, I want to mount this directory from host pc (/var/www/html) to my docker container's /var/www/html directory.

How can this be done? Thanks!

Kshitij Kumar
  • 350
  • 4
  • 17
  • Possible duplicate of [How to mount host directory in docker container?](https://stackoverflow.com/q/23439126/608639), [How to mount host volumes into docker containers in Dockerfile](https://stackoverflow.com/q/26050899/608639), [How do I mount a host directory as a volume in docker](https://stackoverflow.com/q/40905761/608639), etc. – jww Jun 09 '18 at 17:49

1 Answers1

1

You're looking to mount a volume. Check out this documentation: https://docs.docker.com/storage/volumes/

Example:

$ docker run -d \
    --name container-name \
    -v /var/www/html:/var/www/html \
    nginx:latest
brandon-barnett
  • 1,035
  • 9
  • 13
  • It didn't work. I have a custom image in a directory so this will not work as the absolute path will start from Dockerfile directory. – Kshitij Kumar Jun 09 '18 at 15:44
  • Can you describe what you mean by custom image in a directory? Typically volumes have nothing to do with a Dockerfile nor the directory it's sitting in. Just provide an absolute path from your file system – brandon-barnett Jun 09 '18 at 15:47
  • Tried it again with different options. Still not working. The absolute path always starts from the Dockerfile directory. – Kshitij Kumar Jun 09 '18 at 16:18
  • I was using the wrong command. I was mounting volume after image name. – Kshitij Kumar Jun 09 '18 at 16:41