[英]Docker volumes mounting on Windows 8 is not working
I want to run a Docker Compose application on a Windows 8. I made it under a Ubuntu 16.04 and it's perfectly working on it. 我想在Windows 8上运行一个Docker Compose应用程序。我在Ubuntu 16.04下运行它并且它完美地工作。
This Docker Compose run: 这个Docker Compose运行:
The two containers use volumes. 两个容器使用卷。
My .env
file: 我的
.env
文件:
COMPOSE_CONVERT_WINDOWS_PATHS=1
APPLICATION_PATH=//C/Users/my_user/Documents/Development/my_application
My docker-compose.yml
file: 我
docker-compose.yml
文件:
version: '2'
services:
web:
build: ../application-web/
ports:
- "80:80"
tty: true
# Add a volume to link php code on the host and inside the container
volumes:
- ${APPLICATION_PATH}:/usr/share/nginx/html/application
- ${APPLICATION_PATH}/docker_files/docker-assistant:/usr/share/nginx/html/assistant
# Add hostnames to allow devs to call special url to open sites
extra_hosts:
- "localhost:127.0.0.1"
- "assistant.docker:127.0.0.1"
- "application.dev:127.0.0.1"
depends_on:
- custom-php
links:
- custom-php:custom-php
custom-php:
build: ../application-php/
ports:
- "50:50"
volumes:
- ${APPLICATION_PATH}:/usr/share/nginx/html/application
- ${APPLICATION_PATH}/docker_files/docker-assistant:/usr/share/nginx/html/assistant
When I run docker-compose up
, everything goes well. 当我运行
docker-compose up
,一切顺利。 Containers start. 容器开始。 But when I try to reach http://192.168.99.100 in my web browser, I got a 403 error.
但是当我尝试在我的网络浏览器中访问http://192.168.99.100时,我收到403错误。
My investigations show that there is no mounted volumes in the nginx and the php containers: 我的调查显示nginx和php容器中没有挂载的卷:
docker exec -it compose_web_1 bash
ls -la /usr/share/nginx/html/assistant/
shows 节目
drwxr.xr.x 2 root root 80 May 18 15:30 .
drwxr.xr.x 2 root root 4096 May 18 16:10 ..
It seems that Docker cannot mount volumes. 似乎Docker无法安装卷。 Why?
为什么?
APPLICATION_PATH
set as //C:/Users/my_user/Documents/Development/my_application
cannot work because Docker use the ":" character as separator for volume declaration: //C:/Users/my_user/Documents/Development/my_application
的环境变量APPLICATION_PATH
无法工作,因为Docker使用“:”字符作为卷声明的分隔符:
ERROR: Volume //C:/Users/my_user/Documents/Development/my_application://C:/Users/my_user/Documents/Development/my_application has incorrect format, should be external:internal[:mode]
错误:卷// C:/ Users / my_user / Documents / Development / my_application:// C:/ Users / my_user / Documents / Development / my_application格式不正确,应该是external:internal [:mode]
It's not a nginx problem because when I create an index.phtml
file in the folder, I am able to run it: 这不是一个nginx问题,因为当我在文件夹中创建一个
index.phtml
文件时,我能够运行它:
<?php echo 'Hello world!';
Ok, I finally did it! 好的,我终于做到了!
Follow those instructions to be able to access C:\\ inside your containers. 按照这些说明,可以访问容器内的C:\\。
Go get it here: https://www.docker.com/products/docker-toolbox 去吧: https : //www.docker.com/products/docker-toolbox
Install it. 安装它。
Open a Docker Quickstart Terminal. 打开Docker快速启动终端。
Run in it: 在其中运行:
docker run hello-world
Open Virtualbox 打开Virtualbox
Open configuration of the default
virtual machine and go to shared folders
打开
default
虚拟机的配置并转到shared folders
Modify or create a new shared folder by clicking on buttons to the right. 单击右侧的按钮修改或创建新的共享文件夹。 Set options to:
将选项设置为:
C:\\
C
Then validate. 然后验证。
Shutdown the default
virtual machine then restart it. 关闭
default
虚拟机,然后重新启动它。
eG if you have a .env
file: eG如果您有
.env
文件:
COMPOSE_CONVERT_WINDOWS_PATHS=1
APPLICATION_PATH=//C/path_from_C_to_the_folder_you_want_to_share_on_the_volume
/!\\ you need to set COMPOSE_CONVERT_WINDOWS_PATHS
to 1! /!\\ 你 需要 将
COMPOSE_CONVERT_WINDOWS_PATHS
设置为1!
In the Docker Quickstart Terminal: 在Docker快速入门终端中:
Go to your Docker Compose folder, then start it: 转到Docker Compose文件夹,然后启动它:
cd /path_to_your_compose_folder
docker-compose up
The Docker technology rely on Linux namespaces. Docker技术依赖于Linux命名空间。 Without Linux, it can't work.
没有Linux,它无法工作。 To allow use of Docker on a Windows, Docker needs to install a Linux virtual machine.
为了允许在Windows上使用Docker,Docker需要安装Linux虚拟机。 All the containers will run inside it.
所有容器都将在其中运行。
The default
virtual machine is now created and running within Virtualbox, that's why you have to share your folders using Virtualbox. 现在,在Virtualbox中创建并运行
default
虚拟机,这就是您必须使用Virtualbox共享文件夹的原因。
After sharing, the default
virtual machine will have a mounted folder in it with a custom name (in the above example, it's C
but it could be elephant
or whatever). 共享后,
default
虚拟机将在其中安装一个带有自定义名称的文件夹(在上面的示例中,它是C
但它可能是elephant
或其他)。
Finally, Docker will mount volumes from the default
virtual machine to the container: you have to use the name of the default
machine shared folder in your volume declaration (in the above example, it's C
but it could be elephant
or whatever). 最后,Docker会将卷从
default
虚拟机安装到容器中:您必须在卷声明中使用default
机器共享文件夹的名称(在上面的示例中,它是C
但它可能是elephant
或其他)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.