像卷一样将绑定安装添加到Dockerfile [英] Add bind mount to Dockerfile just like volume

查看:66
本文介绍了像卷一样将绑定安装添加到Dockerfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将绑定安装添加到docker文件中,就像在Dockefile中初始化一个卷一样。
有什么办法吗?

I want to add the bind mount to docker file just like I initialise a volume inside Dockefile. Is there any way for it?

推荐答案

一个Dockerfile定义了镜像的构建方式,而不是镜像的使用方式-因此,您无法在Dockerfile。尝试改用 docker-compose 。一个简单的 docker-compose.yml 会为您安装目录,如下所示:

A Dockerfile defines how an image is built, not how it's used - so you can't specify the bind mount in a Dockerfile. Try using docker-compose instead. A simple docker-compose.yml that mounts a directory for you would look like this:

version: '3.1'

services:
  mycontainer:
    image: myimage
    build: .
    volumes:
      - './path/on/docker/host:/path/inside/container'  

build:。是可选的,如果您通过其他方式构建图像,则有时方便地将其全部完成。

The build: . is optional if you're building the image by some other means, but sometimes it's handy to do it all in one.

使用 docker-compose up -d

这篇关于像卷一样将绑定安装添加到Dockerfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆