为什么Docker不编译我的微服务源文件? [英] Why Docker is not compiling my micro-service source files?

查看:103
本文介绍了为什么Docker不编译我的微服务源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Docker。

I've just started to use Docker.

我正在研究另一个开发人员编写的项目。在项目Docker容器中,我有三个微服务(聚合器,分类器,testmicro)。

I'm working on a project coded by another developer. In the project Docker container, I have three micro-services (aggregatore, classificatore, testmicro).

classificatore / 中,我有:

classificatore / Dockerfile

FROM python:3
RUN mkdir /src
ADD requirements.txt /src/.
WORKDIR /src
RUN pip install -r requirements.txt
ADD . /src/.
RUN mkdir -p /tmp/reqdoc
CMD ["python", "main.py"]

我通过运行以下命令构建应用程序:

I build-up the app by running:

docker-compose up -d

我已经意识到Docker不会编译项目文件夹中的源文件,而是使用目录中的源文件 / src 由classificatore / Dockerfile创建。我找不到此目录。

I've realised that Docker is not compiling the source files in the project folder but it is using the ones in the dir /src created by classificatore/Dockerfile. I can't find this dir.

如何告诉docker在我的项目位置中使用文件?

How can I tell docker to use the files in my project location?

我正在使用PyCharm,不知道它是否有用:-)

I'm using PyCharm, don't know if it is an useful info :-)

编辑1

docker-compose.yml

version: '2.1'
services:
  files:
    image: busybox
    volumes:
     [..]

  grafana:
     [..]

  prometheus:
     [..]

  aggregatore:
   [..] 

  classificatore:
    build: classificatore/.
    volumes:    
      - [..]
    volumes_from: 
      - files
    ports: 
      - [..]
    command: ["python", "/src/main.py"]
    depends_on: 
      rabbit:
        condition: service_healthy

  testmicro:
    [..]    
  rabbit:
    [..]


推荐答案

docker-compose up -d 将为声明构建的服务构建映像,前提是且仅当本地Docker注册表中不存在映像时。如果您 docker-compose down 并重新开始,则下一个调用将仅使用已存在的映像启动容器。

docker-compose up -d will build an image for services that declare a build if and only if no image exists already in your local docker registry. If you docker-compose down and start over, the next call will simply start containers with the already existing image.

要更新现有图像并运行其中的新容器,必须专门要求构建。

To update an existing image and run a new container out of it, you have to specifically ask for a build.

docker-compose build
docker-compose up -d

另一个选项是使用-build 选项。

An other options is to use the --build option.

docker-compose up -d --build

通过检查可能会发现其他有用的情况帮助:

You might find other useful scenarios by inspecting the help:

docker-compose --help
docker-compose build --help
docker-compose up --help

这篇关于为什么Docker不编译我的微服务源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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