Steps to set up and mount shared folders on Windows host and Docker container

Steps to set up and mount shared folders on Windows host and Docker container

Programs in Docker containers often need to access and call data in the host directory, and importing and exporting data every time is very troublesome and laborious.

Next, we will mount the specified folder of the host machine into the Docker container step by step.

1. Open Oracle VM VirtualBox:

2. Click [Settings] -> click [Shared Folders] on the left.

3. Double-click the default [c/Users \\?\c:\Users] to edit it. Here, set the data under the D drive as the mounted shared directory. The name can be modified. Here it is set to "data". Click OK

4. Restart the virtualbox virtual machine, there is a waiting time in between:

5. Create a container and test whether the shared directory can be accessed

Create a container named centos-1 based on the centos image, and use the -v parameter to mount the D:\data directory to the /home directory of the container:

C:\Users\Administrator>docker run -d -it --name centos-1 -v /data:/home centos

9b871d35e1669640dd027a64214b3f78d9faec8b29e91f23aa717d7b7b5036ed

Enter the container:

C:\Users\Administrator>docker exec -it centos-1 /bin/bash

[root@e952aff59318 /]#

Check whether the /home directory is consistent with the local D:\data directory:

[root@e952aff59318 /]# cd home
[root@e952aff59318 home]# ls
a.txt db log sslkey.log

If they are consistent, the mount is successful.

Additional knowledge: Docker image file import and export, support batch

I often need to pull some foreign images at work, but due to network restrictions and other reasons, it is very slow to pull them in the company, so I am used to pulling images from Amazon servers, exporting them and downloading them locally before importing them into the development environment.

1. View the image id

sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
quay.io/calico/node v1.0.1 c70511a49fa1 6 weeks ago 257 MB
hello-world latest 48b5124b2768 2 months ago 1.84 kB
quay.io/coreos/flannel v0.7.0 63cee19df39c 2 months ago 73.8 MB
quay.io/calico/cni v1.5.5 ada87b3276f3 2 months ago 67.1 MB

2. Select the image to be packaged and execute the packaging command

sudo docker save -o quay.io-calico-node-1.tar quay.io/calico/node

The export file xxx.tar will be generated in the current directory, and then this file will be downloaded to the local

3. Import the above packaged image in the development environment

docker load -i quay.io-calico-node-1.tar

0a43edc59c00: Loading layer 27.59 MB/27.59 MB
69a5574b2581: Loading layer 3.636 MB/3.636 MB
fb0933709f36: Loading layer 3.913 MB/3.913 MB
7384abd120f5: Loading layer 3.859 MB/3.859 MB
e34911610de0: Loading layer 27.06 MB/27.06 MB
d6ec327c8cbe: Loading layer 6.656 kB/6.656 kB
Loaded image ID: sha256:ada87b3276f307a6b1b1ada15820b6c9842fd839fe5cc46ad5db8af81f7fd271

At this point, you can use the local image!

4. Batch import and export image tool

Visit my github to get

The above steps for setting up and mounting shared folders in Windows host and Docker container are all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Implementation of mounting NFS shared directory in Docker container
  • Docker - Summary of 3 ways to modify container mount directories
  • Docker mounts local directories and data volume container operations
  • Solve the problem of docker log mounting
  • Docker starts the elasticsearch image and solves the error after mounting the directory
  • Docker deploys nginx and mounts folders and file operations
  • Detailed explanation of docker nginx container startup and mounting to local
  • Solve the problem of failure to mount files or directories using ./ relative path in docker run

<<:  HTML+CSS realizes scrolling to the element position to display the loading animation effect

>>:  JavaScript to achieve simple provincial and municipal linkage

Recommend

Mobile browser Viewport parameters (web front-end design)

Mobile browsers place web pages in a virtual "...

Regarding the Chinese garbled characters in a href parameter transfer

When href is needed to pass parameters, and the p...

Summary of H5 wake-up APP implementation methods and points for attention

Table of contents Preface Jump to APP method URL ...

Free tool to verify that HTML, CSS and RSS feeds are correct

One trick for dealing with this type of error is t...

Detailed graphic explanation of how to clear the keep-alive cache

Table of contents Opening scene Direct rendering ...

3 ways to correctly modify the maximum number of connections in MySQL

We all know that after the MySQL database is inst...

Implementing a simple calculator based on JavaScript

This article shares the specific code of JavaScri...

Solution to 700% CPU usage of Linux process that cannot be killed

Table of contents 1. Problem Discovery 2. View de...

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:f...

Docker5 full-featured harbor warehouse construction process

Harbor is an enterprise-level registry server for...

Navicat connection MySQL error description analysis

Table of contents environment Virtual Machine Ver...

How to install rabbitmq-server using yum on centos

Socat needs to be installed before installing rab...

Detailed tutorial on installing Tomcat9 windows service

1. Preparation 1.1 Download the tomcat compressed...

About the overlap of margin value and vertical margin in CSS

Margin of parallel boxes (overlap of double margi...