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

Building FastDFS file system in Docker (multi-image tutorial)

Table of contents About FastDFS 1. Search for ima...

How to enable MySQL remote connection in Linux server

Preface Learn MySQL to reorganize previous non-MK...

Similar to HTML tags: strong and em, q, cite, blockquote

There are some tags in XHTML that have similar fu...

Detailed explanation of CocosCreator project structure mechanism

Table of contents 1. Project folder structure 1. ...

Detailed explanation of how MySQL solves phantom reads

1. What is phantom reading? In a transaction, aft...

HTML+CSS to achieve charging water drop fusion special effects code

Table of contents Preface: accomplish: Summarize:...

Common array operations in JavaScript

Table of contents 1. concat() 2. join() 3. push()...

Detailed steps to implement the Excel import function in Vue

1. Front-end-led implementation steps The first s...

Design perspective technology is an important capital of design ability

A design soldier asked: "Can I just do pure ...

Summary of several commonly used CentOS7 images based on Docker

Table of contents 1 Install Docker 2 Configuring ...

MySQL horizontal and vertical table conversion operation implementation method

This article uses examples to illustrate how to i...

How to use Nginx proxy to surf the Internet

I usually use nginx as a reverse proxy for tomcat...