Windows 8上安装的Docker卷无法正常工作 [英] Docker volumes mounting on Windows 8 is not working
问题描述
上下文
我想在Windows 8上运行Docker Compose应用程序。我在Ubuntu 16.04下制作了它,并且可以完美运行。
此Docker Compose运行:
- nginx
- php-fpm
两个容器使用卷。
文件
我的 .env
文件:
COMPOSE_CONVERT_WINDOWS_PATHS = 1
APPLICATION_PATH = // C / Users / my_user / Documents / Development / my_application
我的 docker-compose.yml
文件:
版本: 2
服务:
网站:
构建:../ application-web /
端口:
- 80:80
tty:true
#添加一个卷以链接主机上和容器内的php代码
卷:
-$ {APPLICATION_PATH}:/ usr / share / nginx / html / application
-$ {APPLICATION_PATH} / docker_files / docker-assistant:/ usr / share / ng inx / html / assistant
#添加主机名以允许开发人员调用特殊的url来打开站点
extra_hosts:
- localhost:127.0.0.1
- assistant.docker: 127.0.0.1
- application.dev:127.0.0.1
depends_on:
-自定义php
链接:
-自定义php:custom-php
自定义php:
构建:../ application-php /
端口:
- 50:50
数量:
-$ {APPLICATION_PATH}:/ usr / share / nginx / html / application
-$ {APPLICATION_PATH} / docker_files / docker-assistant:/ usr / share / nginx / html / assistant
问题
当我运行 docker-compose
,一切顺利。容器启动。
但是当我尝试在网络浏览器中访问
打开默认值
虚拟机的配置,然后转到共享文件夹
修改或创建新的共享单击右边的按钮打开文件夹。将选项设置为:
-
C:\
-
C
- 自动挂载
- 永久配置
然后验证。
4。激活共享
关闭默认值
虚拟机,然后重新启动它。
5。设置路径
e.G。如果您有 .env
文件:
COMPOSE_CONVERT_WINDOWS_PATHS = 1
APPLICATION_PATH = // C / path_from_C_to_the_folder_you_want_to_share_on_the_volume
/!\ you 需要 将 COMPOSE_CONVERT_WINDOWS_PATHS
设置为1!
6。在Docker快速入门终端中启动您的撰写
转到Docker Compose文件夹,然后启动它:
cd / path_to_your_compose_folder
docker-compose up
我为什么要这样做?
Docker技术依赖Linux名称空间。没有Linux,它将无法正常工作。为了允许在Windows上使用Docker,Docker需要安装Linux虚拟机。所有容器都将在其中运行。
code> default 虚拟机现已创建并在Virtualbox中运行,这就是为什么必须使用Virtualbox共享文件夹的原因。
共享后,默认
虚拟机将在其中安装一个带有自定义名称的文件夹(在上面例如,它是 C
,但它可能是 elephant
或其他)。
最后,Docker会将卷从 default
虚拟机装载到容器:您必须使用名称卷声明中的默认
计算机共享文件夹(在上面的示例中,它是 C
,但可能是大象
或其他)。
Context
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.
This Docker Compose run:
- nginx
- php-fpm
The two containers use volumes.
Files
My .env
file:
COMPOSE_CONVERT_WINDOWS_PATHS=1
APPLICATION_PATH=//C/Users/my_user/Documents/Development/my_application
My docker-compose.yml
file:
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
Problem
When I run docker-compose up
, everything goes well. Containers start.
But when I try to reach http://192.168.99.100 in my web browser, I got a 403 error.
My investigations show that there is no mounted volumes in the nginx and the php containers:
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. Why?
Other information
- I am using the Docker Toolbox: https://www.docker.com/products/docker-toolbox
- I know that's the good IP address because when I try to reach it in my web browser, I see my nginx container displaying logs.
- The environment variable
APPLICATION_PATH
set as//C:/Users/my_user/Documents/Development/my_application
cannot work because Docker use the ":" character as separator for volume declaration: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]
It's not a nginx problem because when I create an
index.phtml
file in the folder, I am able to run it:<?php echo 'Hello world!';
Ok, I finally did it!
TL;DR
Follow those instructions to be able to access C:\ inside your containers.
1. Install the Docker Toolbox
Go get it here: https://www.docker.com/products/docker-toolbox
Install it.
2. Run a Hello world
Open a Docker Quickstart Terminal.
Run in it:
docker run hello-world
3. Share C:\ with Docker
Open Virtualbox
Open configuration of the default
virtual machine and go to shared folders
Modify or create a new shared folder by clicking on buttons to the right. Set options to:
C:\
C
- Auto mount
- Permanent configuration
Then validate.
4. Activate sharing
Shutdown the default
virtual machine then restart it.
5. Set your paths
e.G. if you have a .env
file:
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!
6. Start your Compose
In the Docker Quickstart Terminal:
Go to your Docker Compose folder, then start it:
cd /path_to_your_compose_folder
docker-compose up
Why have I to do that? It's so complicated!
The Docker technology rely on Linux namespaces. Without Linux, it can't work. To allow use of Docker on a Windows, Docker needs to install a Linux virtual machine. 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.
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).
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).
这篇关于Windows 8上安装的Docker卷无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!