简体   繁体   English

什么是在Windows中使用docker并具有基本文件共享可能性的简单工作流程?

[英]What is a simple workflow to use docker in Windows with a basic file sharing possibility?

为简单起见,请使用ubuntu映像作为示例。

I often find it easier to use docker-compose, particularly if there's a high chance I'll want to both mount-volumes and link the container to another container at some point in the future. 我经常发现使用docker-compose更容易,特别是如果我很有可能想要装载卷在将来的某个时候将容器链接到另一个容器。

  1. Create a folder for working in, say "ubuntu". 创建一个工作文件夹,比如“ubuntu”。
  2. In the "ubuntu" folder, create another folder called "files" 在“ubuntu”文件夹中,创建另一个名为“files”的文件夹
  3. Create a file in that folder called "docker-compose.yml". 在该文件夹中创建一个名为“docker-compose.yml”的文件。 In this file, enter: 在此文件中,输入:

     ubuntucontainer: image: "ubuntu:latest" ports: - "80:80" volumes: - ./files:/files 
  4. Whenever you need to start the box, navigate to "ubuntu" and type docker-compose up . 每当您需要启动该框时,请导航至“ubuntu”并键入docker-compose up To stop again, use docker-compose stop . 要再次停止,请使用docker-compose stop

The advantage of using docker compose is that if you ever want to link-up a database container this can be done easily by adding another container to the yaml file, and then in the ubuntucontainer container adding a links section. 使用docker compose的优点是,如果您想要链接数据库容器,可以通过向yaml文件添加另一个容器,然后在ubuntucontainer容器中添加一个links部分来轻松完成。

Not to mention, docker-compose up is quite minimal on the typing. 更不用说,对于打字来说, docker-compose up是非常小的。

(Also, forwarding the ports with 80:80 may not be strictly necessary, it depends on what you want the box to do.) (另外,使用80:80转发端口可能不是绝对必要的,这取决于你想要盒子做什么。)

TL;DR version: TL; DR版本:

  1. Open Docker Quickstart Terminal . 打开Docker快速入门终端 If it is already open, run $ cd ~ 如果它已经打开,请运行$ cd ~
  2. Run this once : $ docker run -it -v /$(pwd)/ubuntu:/windows --name ubu ubuntu 运行一次$ docker run -it -v /$(pwd)/ubuntu:/windows --name ubu ubuntu
  3. To start every time: $ docker start -i ubu 每次开始: $ docker start -i ubu

You will get an empty folder named ubuntu in your Windows user directory. 您将在Windows用户目录中获得一个名为ubuntu的空文件夹。 You will see this folder with the name windows in your ubuntu container. 您将在ubuntu容器中看到名为windows此文件夹。

Explanation: 说明:

  1. cd ~ is for making sure you are in Windows user directory. cd ~用于确保您在Windows用户目录中。
  2. -it stands for interactive, so you can interact with the container in the terminal environment. -it代表交互式,因此您可以在终端环境中与容器进行交互。 -v host_folder:container_folder enables sharing a folder between the host and the container. -v host_folder:container_folder允许在主机和容器之间共享文件夹。 The host folder should be inside the Windows user folder. 主机文件夹应位于Windows用户文件夹中。 /$(pwd) translates to //c/Users/YOUR_USER_DIR in Windows 10. --name ubu assigns the name ubu to the container. /$(pwd)转换为Windows 10中的//c/Users/YOUR_USER_DIR --name ubu name ubu将名称ubu分配给容器。
  3. -i stands for interactive -i代表互动

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

相关问题 Docker:防火墙阻止 Windows 和容器之间的文件共享 - Docker: A firewall is blocking file Sharing between Windows and the containers Docker:使用Docker Toolbox在Windows上共享卷 - Docker: Sharing a volume on Windows with Docker Toolbox 在 Docker 文件中使用 linux 命令并在 windows 上构建 - Use linux commands in Docker file and build on windows 需要制作一个简单的Windows应用程序,我应该使用什么样的语言? - need to make a simple Windows app, what languague should I use? Windows文件共享:哪些ACE AccessMask标志对应于不同的共享权限? - Windows file sharing: What ACE AccessMask flags correspond to the different share permissions? 是什么阻止 windows 删除正在使用的文件? - What prevents windows from deleting a file that is in use? 为什么Go在Windows上使用cgo来获得简单的File.Write? - Why Go use cgo on Windows for a simple File.Write? 我在Windows上使用vagrant + docker时出现文件系统问题 - file system issue when i use vagrant+docker on windows Windows上的基本python select有什么问题? - What's wrong with this basic python select on windows? 在 Windows 系统的 docker build 上启动基本的 bash 脚本 - launch basic bash script on docker build from windows system
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM