迹忆客 EN >

当前位置:主页 > 学无止境 > 操作系统 > Docker >

了解 Docker 中的卷指令

作者:迹忆客 最近更新:2023/04/16 浏览次数:

在 Docker 中,我们可以创建单独的镜像、容器和卷。 每当我们启动容器时都可以挂载卷。

如果我们可以在 Docker 中手动完成,我们可以通过使用名为 Dockerfile 的文件的构建过程来自动化它。

本文将讨论通过 Dockerfile 在 Docker 中构建、创建和装载卷。


了解 Docker 中的 VOLUME 指令

使用 Dockerfile 时,我们使用多个指令来自动构建单个或多个容器。 这些指令的一个例子是 VOLUME 指令。

在 Dockerfile 中,它应该看起来像这样:

FROM ubuntu
RUN mkdir /samplevol
VOLUME /samplevol

但是,当我们尝试在 Dockerfile 中输入 VOLUME 指令的值时,会出现一些混乱。 使用 VOLUME 指令时,我们需要了解这不是我们指示容器外部 Docker 卷位置的地方。

取而代之的是,VOLUME 指令是我们告诉目标的地方,当容器已经运行时,我们将在容器内的哪个位置挂载我们的外部 Docker 卷。

如果我们还记得的话,当我们运行一个容器时,我们可以使用 --volume 或 -v 参数来挂载一个特定的卷。 但是,此参数还有其他用途。

例如,使用 --volume 参数,我们可以指定应该在哪个位置挂载 Docker 卷。

示例命令:

$ docker run --volume=/volumesd:/samplevol sushi_bake

在上面的命令中,**/volumesd** 目录是卸载的 Docker 卷的位置。 /samplevol 目录是我们将在创建和运行的容器中安装 Docker 卷的地方。

此外,**/samplevol** 目录是 Dockerfile 中 VOLUME 指令的正确值。

或者,我们可以通过不在 Dockerfile 中添加 VOLUME 指令来避免混淆。 如果我们没有在 VOLUME 指令中添加挂载点,Docker 会为要挂载的卷分配一个默认位置。

该位置通常在 /var/lib/docker/volumes 下。

转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处

本文地址:

相关文章

Solution to incorrect access log time when deploying Nginx in Docker

发布时间:2025/03/26 浏览次数:165 分类:Docker

In the process of operating the website, I never took the logs too seriously. Although logging was turned on, I never analyzed the logs carefully. Today, when I looked at the logs on a whim, I found that the recorded time was 8 hours less t

Docker deploys nginx php application

发布时间:2025/03/26 浏览次数:131 分类:Docker

I'm learning docker recently. I'm learning by building an nginx+php development environment example. Here I record the build process. First, give a docker-compose.yml deployment configuration file version: '3' services: nginx: container_nam

How to use Docker to image a Node.js web application

发布时间:2025/03/26 浏览次数:107 分类:Docker

Docker is a containerization platform that simplifies the packaging and execution of applications. Containers run as independent processes with their own file systems, but share the kernel of their host machine. Docker has attracted much at

Start a Bash terminal in a new Docker container

发布时间:2025/03/26 浏览次数:97 分类:Docker

Docker containers are a standard unit for packaging all the dependencies of an application, allowing us to easily run them in any environment. Containers have become very popular recently, and most developers now rely heavily on containers

Passing environment variables to containers in Docker

发布时间:2025/03/26 浏览次数:124 分类:Docker

This article will introduce how to pass environment variables to containers in Docker. Passing environment variables to containers in Docker using the -e and tags -env We will first see how to create environment variables and pass them to t

Install Docker using Homebrew

发布时间:2025/03/26 浏览次数:202 分类:Docker

There is no doubt that Docker containers have revolutionized the way we develop and deploy applications. They provide developers with the ability to package applications and dependencies in an isolated environment. Recently, we've seen wide

Enforce clean build of images in Docker

发布时间:2025/03/26 浏览次数:87 分类:Docker

This article discusses and demonstrates how to enforce clean builds of images in Docker. Building images in Docker We will use a simple Flask application to demonstrate this concept. my-app Create a app.py simple application named in the ho

Running a Docker instance from a Dockerfile

发布时间:2025/03/26 浏览次数:140 分类:Docker

Docker containers have undoubtedly become the standard unit for managing software and dependencies in different environments. When using real applications, you must create a docker file before building the container image of the application

扫一扫阅读全部技术教程

社交账号
  • https://www.github.com/onmpw
  • qq:1244347461

最新推荐

教程更新

热门标签

扫码一下
查看教程更方便