zoukankan      html  css  js  c++  java
  • Docker 数据管理-bind mount

    Use bind mounts

    Bind mounts have been around since the early days of Docker. Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its full or relative path on the host machine. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.

    Start a container with a bind mount

    Consider a case where you have a directory source and that when you build the source code, the artifacts are saved into another directory source/target/. You want the artifacts to be available to the container at /app/, and you want the container to get access to a new build each time you build the source on your development host. Use the following command to bind-mount the target/ directory into your container at /app/. Run the command from within the source directory. The $(pwd) sub-command expands to the current working directory on Linux or macOS hosts.

    The --mount and -v examples below produce the same result. You can’t run them both unless you remove the devtest container after running the first one.

    --mount 语法格式:

    $ docker run -d 
      -it 
      --name devtest 
      --mount type=bind,source="$(pwd)"/target,target=/app 
      nginx:latest

    -v 语法格式:

    $ docker run -d 
      -it 
      --name devtest 
      -v "$(pwd)"/target:/app 
      nginx:latest

    Mounting into a non-empty directory on the container

    If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured(覆盖) by the bind mount. This can be beneficial, such as when you want to test a new version of your application without building a new image. However, it can also be surprising and this behavior differs from that of docker volumes.

  • 相关阅读:
    window.location 对象所包含的属性
    控制器如何获取一条url中存在多个Id
    js 生成GUID
    JS控制前端控件的显示与隐藏
    ASP.NET CORE根据后台数值在razor页面进行判断单选按钮选中
    Selectize 控件使用以及js执行文件的时间差问题
    理解css中的position属性
    本地预览的vue项目,在githubpage静态展示
    关于img底部空白
    [优化]Steamroller-freecodecamp算法题目
  • 原文地址:https://www.cnblogs.com/vincenshen/p/8605958.html
Copyright © 2011-2022 走看看