如何以最小的停机时间重新加载docker-compose容器中的环境variables?

泊坞窗,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文件,如何重新加载容器以最less的停机时间使用新的环境variables?

如果您使用docker-compose运行yml,则可以运行docker-compose up -d ,然后重新创build所有已更改的容器,并保留所有未更改的服务。

 $ 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 

如果将容器作为docker stack deploy -c docker-compose.yml以版本3文件格式运行,则可以执行服务的滚动更新,以便在运行服务的多个实例时防止任何停机。 这个function还是很新的,你需要1.13.1来解决更新的一些问题,并且像这个新东西一样,错误仍然在制定中。