简体   繁体   English

docker-compose在docker-compose.yml中具有多个服务的构建

[英]docker-compose build with multiple services in docker-compose.yml

I am new to docker-compose, I have built a simple web application using flask and redis and it works fine in my localhost, my question is how to push this web app including the python and redis images to docker hub and pull that image from a different machine. 我是docker-compose的新手,我使用flask和redis构建了一个简单的Web应用程序,并且在我的本地主机上运行良好,我的问题是如何将包含python和redis图像的该Web应用程序推送到docker hub并从中提取该图像不同的机器。

I usually do docker-compose build, docker push 我通常会做docker-compose build,docker push

version: '3'
services:
 web:
  build: .
  image: "alhaffar/flask_redis_app:2.0"
  ports:
   - "8088:5000"
  depends_on:
   - redis
 redis:
  image: "redis:alpine"

the Dockerfile Dockerfile

FROM python:3.7

# CHANGE WORKIN DIR AND COPY FILES
WORKDIR /code
COPY . /code

# INSTALL REQUIRED PACAKGES
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# RUN THE APP
CMD ["python", "./main.py"]

when I try to pull the image into a different machine and issue docker run, it runs only the python image without redis image. 当我尝试将映像拉入另一台计算机并发出docker run时,它仅运行python映像而没有redis映像。

how I can run all images 我如何运行所有图像

Dockerhub and other docker registries work with images. Dockerhub和其他Docker注册表使用映像。 Docker-compose is just an abstraction which helps to set up a bunch of images, that can work together, by using one configuration-file - docker-compose. Docker-compose只是一个抽象,它通过使用一个配置文件docker-compose来帮助建立一堆可以协同工作的映像。 There is nothing like docker-compose registries. 没有像docker-compose注册表那样的东西。 Then if you have your docker-compose file on the other machine you just use docker-compose up and images should be pulled - assuming they are published to some registry (public/private). 然后,如果您在另一台机器上有docker-compose文件,则只需使用docker-compose up并应将图像拉出-假设它们已发布到某个注册表(公共/私有)。 Image with your app should be published by you and refis will be taken form dockerhub registry, if you are using redis official image. 如果您使用的是Redis官方映像,则应用程序的映像应由您发布,并且refs将通过dockerhub注册表获取。

Docker-compose is helpful when you are doing some local development and want to set up your working environment quickly. 当您进行一些本地开发并希望快速设置工作环境时,Docker-compose会很有帮助。 If you want to set up this environment on other machine you would have to share the docker-compose file with them and have the docker and docker-compose installed on that other machine. 如果要在其他计算机上设置此环境,则必须与它们共享docker-compose文件,并在该另一台计算机上安装docker和docker-compose。

If your docker-compose is configured to build some image on start, you can still push this image using docker-compose push command. 如果您的docker-compose配置为在启动时构建一些映像,您仍然可以使用docker-compose push命令推送此映像。

With your Docker Compose Script you do two things: 使用Docker Compose脚本,您可以做两件事:

  1. Build your Flask App —> Image 1 构建您的Flask应用程序->图片1
  2. Pull and run Redis —> Image 2 拉并运行Redis —>图2

If you push Image 1 to DockerHub and pull it on an other machine, you are missing the second Image. 如果将映像1推入DockerHub并将其拉到另一台机器上,则会丢失第二个映像。

What you want to do is run the Docker compose script on the second machine without the build line. 您想要做的是在没有build行的第二台机器上运行Docker compose脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM