我们需要将docker-compose.yml转移到生产服务器吗? [英] Do we need to transfer docker-compose.yml to Production server?
问题描述
我对docker和docker compose还是很陌生。我设法构建了映像并将其推送到Docker Hub。我构建的应用程序很简单,包含2张图像 php7-apache
和 mysql
官方图像。全部在 docker-compose.yml
中声明。
I'm pretty new to docker and docker compose. I have managed to build my image and push it to Docker Hub. The app I built is simple and consists of 2 images php7-apache
and mysql
offical images. All declared in docker-compose.yml
.
我通知我的团队使用 docker pull ...
从Docker Hub存储库中提取我构建的映像。使用 docker run -d ...
启动它。但是,当我们在生产服务器中运行 docker ps
时,仅运行1个进程,但没有MySQL。
I informed my team to pull the image I built from my Docker Hub repository using docker pull ...
and start it using docker run -d ...
. But when we run docker ps
in the production server, only 1 process is running but no MySQL.
通常,当我使用 docker-compose up
在本地运行时,我在终端机上得到了这个:
使用默认驱动程序
创建网络 myntrelease_default创建myntrelease_mysql_1
创建myntrelease_laravel_1
然后,我可以使用 docker-compose exec mysql bash
并在那里调整一些表。到现在为止还挺好。
Usually, when I run locally using docker-compose up
I get this in the terminal:
Creating network "myntrelease_default" with the default driver
Creating myntrelease_mysql_1
Creating myntrelease_laravel_1
I can then access the MySql using docker-compose exec mysql bash
and tweak some tables there. So far so good.
问题是当生产服务器不可用时,如何在生产服务器中使用 docker-compose.yml
图像本身?
Question is how can I use docker-compose.yml
in the production server when it's not available because its in the image itself?
推荐答案
简短答案:是的,您需要在生产环境中使用docker-compose.yml。
Short answer: Yes, you need the docker-compose.yml in the production environment.
说明:每个图像都是独立的。由于您的映像独立于MySQL映像(至少我从您的问题中了解到),并且docker-compose.yml定义了两者之间的关系(例如,如何在php7-apache映像中访问MySQL),在生产中需要docker-compose.yml。即使您只有一个映像,使用docker-compose.yml通常也很好,这样可以清楚地定义设置和配置,例如卷安装,端口等。
Explanation: Every image is independent. Since your image is independent of MySQL image (at least that's what I understand from your questions), and docker-compose.yml defines the relationship between the two (eg. how MySQL is accessible in the php7-apache image), then you definitely need the docker-compose.yml in production. Even if you only have a single image its usually good to use docker-compose.yml so that settings and configuration like volume mounts, ports etc. can be clearly defined.
这篇关于我们需要将docker-compose.yml转移到生产服务器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!