21

I'm trying to setup a developer environment through a Docker container on my Windows 7 computer.

I've installed Docker toolbox for Windows.

I have an image with Apache and PHP 5.6 within, and here it is:

FROM php:5.6.15-apache

RUN apt-get update && apt-get install -y \
apt-utils vim git php5-mysql php5-memcache php5-memcached php5-intl \
wget
RUN apt-get install libapache2-mod-php5 -y -o Dpkg::Options::="--force-confdef"
RUN docker-php-ext-install mbstring
RUN docker-php-ext-install pdo pdo_mysql
RUN apt-get install libcurl4-gnutls-dev -y
RUN docker-php-ext-install curl
RUN a2enmod rewrite

ENV APACHE_RUN_USER myname
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

EXPOSE 80

COPY php.ini /usr/local/etc/php/php.ini
COPY apache-config.conf /etc/apache2/sites-enabled/000-default.conf
RUN echo "ServerName 127.0.1.1" >> /etc/apache2/apache2.conf

This image is created, and I can see it when I run "docker images" in the Docker quickstart terminal.

In my apache-config.conf, I just have a tiny virtual host to access a test website with just an index.php file.

Then I try to create the container in the Docker quickstart terminal:

docker run --name=php5.6_container --rm -v "//c/sites:/var/www/html" -p 80:80 -p 8080:8080 php5.6

I get the following error:

AH00112: Warning: DocumentRoot [/var/www/html/test] does not exist
AH00112: Warning: DocumentRoot [/var/www/html/test] does not exist
[Tue Dec 08 16:36:37.703143 2015] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) configured -- resuming normal operations
[Tue Dec 08 16:36:37.703733 2015] [core:notice] [pid 1] AH00094: Command line: '
apache2 -D FOREGROUND'

It seems like my volume option is not taken into account. And the container is not created.

What could I be doing wrong?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jiboulex
  • 2,963
  • 2
  • 18
  • 28

5 Answers5

59

See the note for Windows and Mac at https://docs.docker.com/engine/userguide/dockervolumes/#mount-a-host-directory-as-a-data-volume. Particularly:

If you are using Docker Machine on Mac or Windows, your Docker daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory.

Basically, you will need to move your site files to somewhere such as c:\Users\sites and then mount using something like suggested in documentation:

docker run --name=php5.6_container --rm -v "/c/Users/sites:/var/www/html" -p 80:80 -p 8080:8080 php5.6
Andy Shinn
  • 26,561
  • 8
  • 75
  • 93
  • Thank you sir ! On to the next step, I have another question if you might have an idea : Now that my container is up with apache running, I'm trying to reach it in the browser but I can't do that. I tried to inspect my container but I found no IP address ("IPAddress" : "") and when I tried to edit the /etc/hosts file on the container to add 127.0.0.1 test.loc, and restarted apache2 service, it stopped my container and my edit were not saved.. any idea ? – jiboulex Dec 14 '15 at 08:20
  • 2
    That probably warrants a new question then. I'd rather not troubleshoot subsequent problems as comments. – Andy Shinn Dec 14 '15 at 18:35
  • This answer is perfectly valid. However, there are also [other ways of using Docker on Windows](https://medium.com/devopslinks/hey-docker-why-you-hate-windows-so-much-de7a7aa4dd7) – Grzegorz Gajos Dec 21 '18 at 12:09
6
  • Open "Oracle VM VirtualBox"
  • Once "default is selected" click on "configuration"
  • Go to "Sheared Folders" Add the desired Folder
  • Then restart default by typing in your console

    docker-machine restart default

Claude Janz
  • 221
  • 2
  • 3
4

Step 1: C:/Program Files/Oracle/VirtualBox/VBoxManage sharedfolder add default -name $shared_folder -hostpath d:/data

To show shared folders:

VBoxManage showvminfo default | less

Step 2(a): mount -t vboxsf -o uid=1000,gid=50 $shared_folder /data

Step 2(b): Adding an automount to boot2docker

While logged into the machine, edit/create (as root) /mnt/sda1/var/lib/boot2docker/bootlocal.sh by adding below block to the file, sda1 may be different for you...

mkdir -p /data mount -t vboxsf -o uid=1000,gid=50 $shared_folder /data

Then, docker-machine restart default

Step 3: Adding volume when running the container(gogs as example) docker run --name=gogs -rm --net=host -d -v /fuple:/data gogs/gogs

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
langdead
  • 149
  • 1
  • 5
0

I think for Docker volume options, double quotes are not required:

docker run --name=php5.6_container --rm -v //c/sites:/var/www/html -p 80:80 -p 8080:8080 php5.6

Check if it is working. I am not sure.

See example of volume mapping at Manage data in containers.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
0

The message is a "WARNING" not an error message. Are you sure your container is not created ? Have you checked with the command "docker ps -a" ?

If the message is the root cause of your problem, you should sort out the non-existence of /var/www/html/test inside your container. If it is not needed, you should removed it from apache configuration (probably inside the file /etc/apache2/sites-enabled/000-default.conf or /etc/apache2/apache2.conf).

If /var/www/html/test is needed, you could try and add

RUN mkdir /var/www/html/test

inside your Dockerfile in order to make sure the directory exists.

Also, in order to try debugging the problem, you might want to try running the container without using the volume. If there is no error, you should then enter the container ("docker exec -it php5.6_container bash") in order to debug the potential problem inside your container and check the structure of your container.

iclman
  • 1,218
  • 9
  • 21
  • I checked after the run command with docker ps -a but no container was created, I ra the command again without the quotes in the volume options and I had the same error but the container was created this time. I don't wanna run a mkdir command since the test folder is supposed to be in the volume that I'm trying to share with my container :( It works well in Linux but I can't make it work on windows :( :( – jiboulex Dec 12 '15 at 09:58
  • 1
    Are you sure you have actually access to //c/sites from your Docker environment. I have not tried the Docker toolbox yet. But with the previous version (Boot2Docker), I was preferred using a path in //c/Users/Public. In your case, you might want to copy the directory sites to C:/Users/Public/sites and then try to map your volume with the "-v //c/Users/Public/sites:/var/www/html" – iclman Dec 13 '15 at 11:50