[英]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更容易,特别是如果我很有可能想要装载卷并在将来的某个时候将容器链接到另一个容器。
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
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
转发端口可能不是绝对必要的,这取决于你想要盒子做什么。)
$ cd ~
如果它已经打开,请运行$ cd ~
$ docker run -it -v /$(pwd)/ubuntu:/windows --name ubu ubuntu
运行一次 : $ docker run -it -v /$(pwd)/ubuntu:/windows --name ubu ubuntu
$ 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
此文件夹。
cd ~
is for making sure you are in Windows user directory. cd ~
用于确保您在Windows用户目录中。 -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
分配给容器。 -i
stands for interactive -i
代表互动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.