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

Detailed explanation of JavaScript to monitor route changes

Table of contents history pushState() Method push...

Use docker to build kong cluster operation

It is very simple to build a kong cluster under t...

Native js encapsulation seamless carousel function

Native js encapsulated seamless carousel plug-in,...

Install Docker environment in Linux environment (no pitfalls)

Table of contents Installation Prerequisites Step...

Detailed explanation of redundant and duplicate indexes in MySQL

MySQL allows you to create multiple indexes on th...

nginx solves the problem of slow image display and incomplete download

Written in front Recently, a reader told me that ...

Introduction to encryption of grub boot program in Linux

Table of contents 1. What is grub encryption 2. g...

React+axios implements github search user function (sample code)

load Request Success Request failed Click cmd and...

A brief explanation of the reasonable application of table and div in page design

At the beginning of this article, I would like to ...

Problems and experiences encountered in web development

<br />The following are the problems I encou...