Docker data volume common operation code examples

Docker data volume common operation code examples

If the developer uses Dockerfile to build the image, they can also declare the data volume when building the image, for example:

FROM nginx
ADD https://www.baidu.com/img/bd_logo1.png /usr/share/nginx/html/
RUN echo "hello docker volume!">/usr/share/nginx/html/index.html
VOLUME /usr/share/nginx/html/

In this way, an anonymous data volume is configured. During operation, data is written to the /usr/share/nginx/html/ directory, which can achieve stateless changes in the container storage layer. View all data volumes

Use the following command to view all data volumes:

docker volume ls

As shown in the figure:

View data volume details

You can view data details according to the volume name, as follows:

docker volume inspect

The execution result is as follows:

Deleting a Data Volume

You can use the docker volume rm command to delete a data volume, or you can use docker volume prune to delete data volumes in batches, as follows:



During batch deletion, all data volumes were not deleted, and one was left. This is because the data volume is still in use. Stop and remove the related containers, and then delete the data volume again to successfully delete it, as shown in the figure:

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker data volumes and data containers detailed introduction and examples
  • Docker data volume, data volume container detailed introduction
  • Introduction to container data volumes in Docker
  • Docker container data volume named mount and anonymous mount issues
  • Two ways to manage volumes in Docker
  • Detailed explanation of Docker container data volumes
  • A brief summary of Docker container data volume mounting
  • Docker mounts a volume to save MySQL data

<<:  JavaScript to achieve slow motion animation effect

>>:  Analysis of MySql index usage strategy

Recommend

A quick solution to the problem of PC and mobile adaptation

When making a web page, we usually need to consid...

Introduction to the use of alt and title attributes of HTML img tags

When browser vendors bend the standards and take i...

Detailed explanation of several methods of JS array dimensionality reduction

Dimensionality reduction of two-dimensional array...

Detailed explanation of Linux system directories sys, tmp, usr, var!

The growth path from a Linux novice to a Linux ma...

Tutorial on installing VMWare15.5 under Linux

To install VMWare under Linux, you need to downlo...

How to dynamically add a volume to a running Docker container

Someone asked me before whether it is possible to...

Some tips for writing high-performance HTML applications

How can you improve web page performance? Most de...

Dynamic starry sky background implemented with CSS3

Result:Implementation Code html <link href=...

B2C website user experience detail design reference

Recently, when using Apple.com/Ebay.com/Amazon.co...

Vue implements a draggable tree structure diagram

Table of contents Vue recursive component drag ev...

【HTML element】Detailed explanation of tag text

1. Use basic text elements to mark up content Fir...