简体   繁体   English

在Windows 8上安装的Docker卷无法正常工作

[英]Docker volumes mounting on Windows 8 is not working

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. 我想在Windows 8上运行一个Docker Compose应用程序。我在Ubuntu 16.04下运行它并且它完美地工作。

This Docker Compose run: 这个Docker Compose运行:

  • nginx nginx的
  • php-fpm PHP-FPM

The two containers use volumes. 两个容器使用卷。

Files

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

Problem 问题

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? 为什么?

Other information 其他信息

  • I am using the Docker Toolbox: https://www.docker.com/products/docker-toolbox 我正在使用Docker工具箱: 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. 我知道这是一个很好的IP地址,因为当我尝试在我的网络浏览器中访问它时,我看到我的nginx容器显示了日志。
  • 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: 设置为//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! 好的,我终于做到了!

TL;DR TL; DR

Follow those instructions to be able to access C:\\ inside your containers. 按照这些说明,可以访问容器内的C:\\。

1. Install the Docker Toolbox 1.安装Docker Toolbox

Go get it here: https://www.docker.com/products/docker-toolbox 去吧: https//www.docker.com/products/docker-toolbox

Install it. 安装它。

2. Run a Hello world 2.运行Hello世界

Open a Docker Quickstart Terminal. 打开Docker快速启动终端。

Docker快速启动终端已打开

Run in it: 在其中运行:

docker run hello-world

3. Share C:\\ with Docker 3.与Docker共享C:\\

Open Virtualbox 打开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
  • Auto mount 自动安装
  • Permanent configuration 永久配置

Then validate. 然后验证。

在此输入图像描述

4. Activate sharing 4.激活共享

Shutdown the default virtual machine then restart it. 关闭default虚拟机,然后重新启动它。

5. Set your paths 5.设置你的路径

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!

6. Start your Compose 6.开始撰写

In the Docker Quickstart Terminal: 在Docker快速入门终端中:

Docker快速启动终端已打开

Go to your Docker Compose folder, then start it: 转到Docker Compose文件夹,然后启动它:

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. 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. 所有容器都将在其中运行。

Docker堆栈解释

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或其他)。

Docker文件夹共享说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM