本文介绍了将目录绑定到Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个测试项目,该项目需要项目目录之外的模块.该项目文件夹位于docker中,我想将该模块目录绑定到我项目的docker容器中.甚至有可能做到这一点?还是我问错了问题?顺便说一下,我还是Docker的新手,所以我只是在尝试一些东西.

I'm building a test project that requires a module outside of the project directory. The project folder is in docker, and I would like to bind that module directory to the docker container of my project. Is it even possible to do it? Or am I asking the wrong question? By the way, I'm still new to docker so I'm just trying things out.

推荐答案

我的理解是,您需要将主机文件夹安装到容器中.所以试试这个:

My understand is, you need mount the host folder to the container. So try this:

docker run -v /host/project_folder:/container/project -t avian/project_image bash

解释

  • -v---volume = []绑定安装卷
  • /host/project_folder-主机服务器的文件夹
  • /container/project-容器的文件夹
  • explanation

    • -v - --volume=[] Bind mount a volume
    • /host/project_folder - host server's folder
    • /container/project - container's folder
    • 最新的docker版本(v1.9.1)支持新命令volume.因此,您应该更轻松地在Docker中管理卷.

      The latest docker version (v1.9.1) support a new command volume. So you should be easier to manage volume in docker.

      # For example, I need attach a volume to mysql container.
      docker volume create --name mysql-data
      docker run --name mysql -v mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
      

      这样,您可以随时删除容器mysql,而不会丢失数据库数据.

      With that, you can delete container mysql any time, without lost your database data.

      这篇关于将目录绑定到Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 22:50
查看更多