Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: Sharing a volume on Windows with Docker Toolbox

Tags:

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?

like image 468
jiboulex Avatar asked Dec 08 '15 16:12

jiboulex


People also ask

Can docker volumes be shared?

You can manage volumes using Docker CLI commands or the Docker API. Volumes work on both Linux and Windows containers. Volumes can be more safely shared among multiple containers. Volume drivers let you store volumes on remote hosts or cloud providers, to encrypt the contents of volumes, or to add other functionality.

How do I share files between docker and Windows?

In order to share Windows folders with Docker containers, you first need to configure the "Shared Drives" option in Docker settings. Once the Shared Drives option is configured, you can mount any folder on shared drives with the "-v" (volume) flag.

Can I use docker Toolbox on Windows 10?

Docker Toolbox requires 64-bit Windows 7 (or higher).


3 Answers

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
like image 173
Andy Shinn Avatar answered Oct 25 '22 16:10

Andy Shinn


  • 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

like image 20
Claude Janz Avatar answered Oct 25 '22 16:10

Claude Janz


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

like image 37
langdead Avatar answered Oct 25 '22 17:10

langdead