简体   繁体   中英

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.

  1. Create a folder for working in, say "ubuntu".
  2. In the "ubuntu" folder, create another folder called "files"
  3. Create a file in that folder called "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 . To stop again, use 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.

Not to mention, docker-compose up is quite minimal on the typing.

(Also, forwarding the ports with 80:80 may not be strictly necessary, it depends on what you want the box to do.)

TL;DR version:

  1. Open Docker Quickstart Terminal . If it is already open, run $ cd ~
  2. Run this once : $ docker run -it -v /$(pwd)/ubuntu:/windows --name ubu ubuntu
  3. To start every time: $ docker start -i ubu

You will get an empty folder named ubuntu in your Windows user directory. You will see this folder with the name windows in your ubuntu container.

Explanation:

  1. cd ~ is for making sure you are in Windows user directory.
  2. -it stands for interactive, so you can interact with the container in the terminal environment. -v host_folder:container_folder enables sharing a folder between the host and the container. The host folder should be inside the Windows user folder. /$(pwd) translates to //c/Users/YOUR_USER_DIR in Windows 10. --name ubu assigns the name ubu to the container.
  3. -i stands for interactive

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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