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

Implement a simple data response system

Table of contents 1. Dep 2. Understand obverser 3...

Nginx configuration and compatibility with HTTP implementation code analysis

Generate SSL Key and CSR file using OpenSSL To co...

MySQL index for beginners

Preface Since the most important data structure i...

An article to understand the use of proxies in JavaScript

Table of contents What is an agent Basic knowledg...

CSS to achieve scrolling image bar example code

On some websites, you can often see some pictures...

MySQL database migration quickly exports and imports large amounts of data

Database migration is a problem we often encounte...

Solution to the conflict between two tabs navigation in HTML

Let's start with a description of the problem...

A brief analysis of the differences between undo, redo and binlog in MySQL

Table of contents Preface 【undo log】 【redo log】 【...

MySQL InnoDB MRR Optimization Guide

Preface MRR is the abbreviation of Multi-Range Re...

How to use Vue3 asynchronous data loading component suspense

Table of contents Preface Creating Components Sum...

Building command line applications with JavaScript

Table of contents 1. Install node 2. Install Comm...

How to obtain root permissions in a docker container

First, your container must be running You can vie...

How to turn off eslint detection in vue (multiple methods)

Table of contents 1. Problem Description 2. Probl...