有条件地在docker-compose中安装卷 [英] Mount a volume in docker-compose conditionally

查看:79
本文介绍了有条件地在docker-compose中安装卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 docker-compose.yml 配置。其中一个容器是Tomcat服务器,它在 webapps 目录中部署了一些默认的 .war 文件。

I have a docker-compose.yml configuration. One of the containers there is a Tomcat server and it has some default .war file deployed in webapps directory.

我希望能够传递(覆盖) war 存档,以便由主机上的某些人部署机。我认为最好的办法就是以某种方式切换/覆盖开始 docker-compose 的能力:默认情况下,我要运行webapp( war 文件)放置在容器中,但如果需要,我希望有可能从主机上挂载目录(例如在开发/调试过程中)。

I want to have the ability to pass (override) the war archive to be deployed by some which resides on the host machine. I think the best would be to have ability somehow switch / override starting docker-compose: as a default, I want to run the webapp (war file) which is inside the container, but I want to have a possibility to mount a directory from my host (for example during development / debugging) if need be.

当前,我的 docker-compose.yml 中包含以下行,如果需要默认行,则将其注释掉。

Currently, I have the following line in my docker-compose.yml, which is commented out if I need the default.

volumes:
# By default, there is the latest version of the application already present in the container
# If you want to provider the container with your own .war file, uncomment the following line
# - ./application/webapps:/usr/local/tomcat/webapps

有没有更好的方法来实现这一目标?

Is there a better way how to achieve that?

推荐答案

我将使用 https://docs.docker.com/compose/extends/#example-use-case 来运行指定卷的服务扩展。

Instead of (not) mounting a volume commenting out that line, I would use https://docs.docker.com/compose/extends/#example-use-case to run a service extension that specifies a volume.

我这样做是为了解决两个不同的问题:

I do this to tackle two different problems:


  • 当Docker映像要在生产环境中运行时我不指定卷,并且 我已在开发过程中指定了一个卷,以检查实时更改。

这篇关于有条件地在docker-compose中安装卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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