如何以最短的停机时间在 docker

编程入门 行业动态 更新时间:2024-10-19 08:51:26
本文介绍了如何以最短的停机时间在 docker-compose 容器中重新加载环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

docker-compose.yml

version: '2'
services:
  app:
    build:
      context: .
    command: python src/app.py
    restart: on-failure
    depends_on:
      - db
    environment:
      - TJBOT_DB_HOST=db
      - TJBOT_API_KEY
      - TJBOT_AUTO_QUESTION_TIME
    env_file:
      - .env
  db:
    image: mongo:3.0.14
    volumes:
      - mongodbdata:/data/db
volumes:
  mongodbdata:

如果我更改了 .env 文件,我如何重新加载容器以在最短的停机时间内使用新的环境变量?

If I change the .env file, how could I reload the container to use the new environment variables with minimum downtime?

推荐答案

如果您使用 docker-compose 运行 yml,您只需运行 docker-compose up -d 它将重新创建任何具有更改且所有未更改的服务保持不变的容器.

If you are running the yml with docker-compose, you can just run docker-compose up -d and it will recreate any containers that have changes and leave all unchanged services untouched.

$ cat docker-compose.env2.yml
version: '2'

services:
  test:
    image: busybox
    # command: env
    command: tail -f /dev/null
    environment:
      - MY_VAR=hello
      - MY_VAR2=world
  test2:
    image: busybox
    command: tail -f /dev/null
    environment:
      - MY_VAR=same ole same ole

$ docker-compose -f docker-compose.env2.yml up -d                                               
Creating network "test_default" with the default driver
Creating test_test_1
Creating test_test2_1

$ vi docker-compose.env2.yml # edit the file to change MY_VAR

$ docker-compose -f docker-compose.env2.yml up -d
Recreating test_test_1
test_test2_1 is up-to-date

如果您将容器作为具有版本 3 文件格式的 docker stack deploy -c docker-compose.yml 运行,您可以对服务进行滚动更新,这将防止出现任何停机时间运行多个服务实例.此功能仍然很新,您需要 1.13.1 来解决更新中的一些问题,并且与任何新功能一样,错误仍在解决中.

If you run the containers as a docker stack deploy -c docker-compose.yml with a version 3 file format, you can do a rolling update of the service which will prevent any downtime if you have multiple instances of your service running. This functionality is still very new, you'll want 1.13.1 to fix some of the issues with updates, and as with anything this new, bugs are still being worked out.

这篇关于如何以最短的停机时间在 docker-compose 容器中重新加载环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 04:01:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/795961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最短   时间   docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!