【问题标题】:After building image with docker-compose build image changes are not reflecting使用 docker-compose 构建映像后,映像更改未反映
【发布时间】:2020-12-20 22:29:14
【问题描述】:

当我使用 docker-compose run --service-ports auth-ui 运行 auth-ui 时。我在 auth-ui 中所做的所有更改都正确反映,所以我在更改代码后构建新的 docker 映像,

这是我的 auth-ui 的 docker-compose.yml 文件。

version: "2"
services:
  auth-ui:
    image: openlmis/dev-ui:9.0.2-SNAPSHOT
    ports:
      - "9000:9000"
      - "9876:9876"
    working_dir: /app
    volumes:
      - '.:/app'
    env_file: .env
    volumes_from:
      - ui-components
    depends_on:
      - ui-components
  ui-components:
    image: openlmis/ui-components:7.2.4-SNAPSHOT
    volumes:
      - '/openlmis-ui-components'
  image:
    build: .
    image: openlmis/auth-ui

它被创建为 openlmis/auth-ui:latest。

然后我在 reference-ui 的 docker-compose.yml 中配置该图像

version: "2"
services:
  reference-ui:
    image: openlmis/dev-ui:9.0.2-SNAPSHOT
    working_dir: /app
    volumes:
      - '.:/app'
    ports:
      - "9000:9000"
      - "9876:9876"
    env_file: .env
    volumes_from:
      - auth-ui
      - fulfillment-ui
      - referencedata-ui
      - requisition-ui
      - report-ui
      - stockmanagement-ui
      - cce-ui
      - ui-components
      - ui-layout
    depends_on:
      - auth-ui
      - fulfillment-ui
      - referencedata-ui
      - requisition-ui
      - report-ui
      - stockmanagement-ui
      - cce-ui
      - ui-components
      - ui-layout
  auth-ui:
    image: openlmis/auth-ui:latest
    volumes:
      - '/openlmis-auth-ui'
  fulfillment-ui:
    image: openlmis/fulfillment-ui:6.0.8-SNAPSHOT
    volumes:
      - '/openlmis-fulfillment-ui'
  referencedata-ui:
    image: openlmis/referencedata-ui:5.6.4-SNAPSHOT
    volumes:
      - '/openlmis-referencedata-ui'
  report-ui:
    image: openlmis/report-ui:5.2.5-SNAPSHOT
    volumes:
      - '/openlmis-report-ui'
  requisition-ui:
    image: openlmis/requisition-ui:7.0.4-SNAPSHOT
    volumes:
      - '/openlmis-requisition-ui'
  stockmanagement-ui:
    image: openlmis/stockmanagement-ui:2.0.8-SNAPSHOT
    volumes:
     - '/openlmis-stockmanagement-ui'
  cce-ui:
    image: openlmis/cce-ui:1.0.8-SNAPSHOT
    volumes:
     - '/openlmis-cce-ui'
  ui-components:
    image: openlmis/ui-components:7.2.4-SNAPSHOT
    volumes:
      - '/openlmis-ui-components'
  ui-layout:
    image: openlmis/ui-layout:5.1.8-SNAPSHOT
    volumes:
      - '/openlmis-ui-layout'
  image:
    build: .
    image: openlmis/reference-ui

但是当我尝试使用 docker-compose run --service-ports reference-ui 运行参考 ui 时,我所做的更改并未反映出来。

我错过了什么吗?

【问题讨论】:

  • volumes:volumes_from: 块应该做什么?您是否尝试使用卷在容器之间共享代码,然后在您重建时它们没有得到更新?
  • 是的@David,我也更新了 reference-ui 的 docker-compose.yml。
  • 如果您希望更新卷内容,Docker 不会使用来自镜像的更新内容覆盖卷中的用户数据。能否将所有依赖项都放在dev-ui 镜像的 Dockerfile 中,这样就可以在没有任何卷声明的情况下运行容器?

标签: docker docker-compose node-modules


【解决方案1】:

正如documentation 状态docker-compose run 对服务运行一次性命令,这不是您想要做的。

您要做的是使用第一个docker-compose.yml 构建映像,第二个使用它来创建容器。

因此,在包含第一个docker-compose.yml(您称为docker-compose.yml file of auth-ui)的目录中,您应该运行docker-compose build 来构建映像,并在包含第二个docker-compose.yml 的目录中(您称为reference-ui's docker-compose.yml ) 你应该运行docker-compose up -d 以使用新图像更新你的服务(假设你想在后台运行服务,否则跳过-d)。

docker-compose build 的文档可以在 heredocker-compose up here 找到。

【讨论】:

    【解决方案2】:

    如果您重建映像,则需要从另一个 docker compose 堆栈中删除该容器,以使用新映像启动一个新容器。尝试docker-compose rm -sf auth-ui,然后重试运行命令。

    【讨论】:

    • 感谢@wobr 的建议,实际上我所做的是我在auth ui 服务的登录页面中进行了一些与ui 相关的更改,在参考中添加最新的auth-ui 图像后更改没有反映-ui 的 docker-compose.yml 文件,在 [ docker-compose rm -sf auth-ui ] 登录页面之后根本没有加载。
    • 你在docker-compose rm -sf auth-ui之后做了docker-compose up -d吗?
    猜你喜欢
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    相关资源
    最近更新 更多