简体   繁体   English

挂载Windows驱动器以从Docker访问

[英]Mounting Windows drives to access from Docker

I am looking to use files on my Windows computer in a Docker container. 我希望在Windows电脑上的Docker容器中使用文件。 This is explained here . 在这里解释

My question relates to how to get to the Docker settings dialogue. 我的问题与如何进入Docker设置对话框有关。

I am using Docker Toolbox on Windows 10. When I right-click on the Docker icon from the task bar, I get three options: 我正在Windows 10上使用Docker Toolbox。在任务栏上右键单击Docker图标时,我得到三个选项:

  1. Docker Quick Start Terminal; Docker快速入门终端;
  2. Unpin from taskbar; 从任务栏取消固定; and
  3. close the window. 关闭窗口。

I am not getting settings dialogue box. 我没有得到设置对话框。 How can I see that option? 我如何看到该选项?

Docker toolbox would be using VirtualBox . Docker工具箱将使用VirtualBox
The answer you are referring to is likely to use Docker for Windows with Hyper-V : see " Install Docker for Windows " 您所指的答案可能是将Windows的DockerHyper-V结合使用 :请参阅“ 安装Windows的Docker

Docker for Windows requires Microsoft Hyper-V to run. Windows的Docker需要运行Microsoft Hyper-V。 After Hyper-V is enabled, VirtualBox will no longer work, but any VirtualBox VM images will remain. 启用Hyper-V后,VirtualBox将不再起作用,但是任何VirtualBox VM映像都将保留。
VirtualBox VMs created with docker-machine (including the default one typically created during Toolbox install) will no longer start. 使用docker-machine创建的VirtualBox VM(包括通常在Toolbox安装过程中创建的默认VM)将不再启动。 These VMs cannot be used side-by-side with Docker for Windows. 这些VM不能与Docker Windows版同时使用。 However, you can still use docker-machine to manage remote VMs. 但是,您仍然可以使用docker-machine来管理远程VM。

Install Docker for Windows: 为Windows安装Docker:

  • Docker does not run natively on Windows. Docker不能在Windows上本地运行。

  • If the OS is not Windows 10 pro, Docker is set up through Docker Toolbox. 如果操作系统不是Windows 10专业版,则通过Docker Toolbox设置Docker。

  • Once the Docker is installed through Docker Toolbox, follow the steps below: 通过Docker Toolbox安装Docker之后,请按照以下步骤操作:

Step 1: Click on "Docker Quickstart Terminal" on Windows to launch. 步骤1:在Windows上单击“ Docker Quickstart Terminal”以启动。 This launches a Docker machine - a virtual machine named "default" through Oracle VirtualBox . 这将启动Docker计算机-通过Oracle VirtualBox命名为“ default”的虚拟机。

Step 2: Open up a command prompt window on Windows. 步骤2:在Windows上打开命令提示符窗口。 Since step 1 created the Docker machine, we can issue docker-machine commands from cmd. 自从步骤1创建Docker机器以来,我们可以从cmd发出docker-machine命令。 The command docker-machine ls will list the running virtual machine with its name (default). 命令docker-machine ls将列出正在运行的虚拟机及其名称(默认)。 Note you can create as many virtual machines as you need from cmd using docker-machine create --driver drivername vmname command. 请注意,您可以使用docker-machine create --driver drivername vmname命令从cmd docker-machine create --driver drivername vmname虚拟机。

Step 3: Running the docker client The Docker clients run on a specific virtual machine. 步骤3:运行 Docker客户 Docker客户端在特定的虚拟机上运行。 This means we need to tell the client where the Docker host is (Oracle VirtualBox - not the Windows laptop) and which virtual machine to target. 这意味着我们需要告诉客户端Docker主机在哪里(Oracle VirtualBox-不是Windows笔记本电脑)以及要定位的虚拟机。 The following helps to simplify to target the specific virtual machine. 以下内容有助于简化针对特定虚拟机的目标。

C:\Users\B> docker-machine env --shell cmd default

SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\B\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
SET COMPOSE_CONVERT_WINDOWS_PATHS=true
REM Run this command to configure your shell:
REM     @FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd default') DO @%i

If you just run the following on cmd:
@FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd default') DO @%i

All the above environment variables will be set up. 以上所有环境变量都将被设置。 We can then issue client (Docker) commands from cmd targeting the "default" Docker virtual machine. 然后,我们可以从cmd发出针对(默认)Docker虚拟机的客户端(Docker)命令。

Step 4: Now we want to make the Windows folder available to the Docker virtual machine named "default" so that that the container (or containers) running on that virtual machine can make use of data on this folder. 步骤4:现在,我们希望Windows文件夹可用于名为“默认”的Docker虚拟机,以便在该虚拟机上运行的一个或多个容器可以使用此文件夹上的数据。

Go to the VirtualBox running on your laptop. 转到笔记本电脑上运行的VirtualBox。 Locate the virtual machine "default" and select the settings (this is what I was asking for in my original question) and share the Windows folder /c/Users . 找到虚拟机“默认”并选择设置 (这是我在原始问题中要求的设置 )并共享Windows文件夹/c/Users

[Note: This settings dialogue option is usually available by right clicking on the Docker icon from the system tray, if Docker has been installed directly on Windows (10 pro).] [注意:如果直接在Windows(10专业版)上安装了Docker,通常可以通过右键单击系统托盘中的Docker图标来使用此设置对话框选项。

Now issue the command from cmd: 现在从cmd发出命令:

docker run -it --name suorsa -v /c/Users:/datavol ImageName:latest

The folder /c/Users is now available for access as in /datavol for the containers. 可以在容器的/datavol访问/c/Users文件夹。

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

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