Docker Stack Deploy not updating environment settings

105 views Asked by At

Given the following compose file:

version: '3.6'

services:
  hello-world:
    image: hello-world
    environment:
     - test:test

If I deploy it using docker stack deploy -c docker-compose.yml test, then modify the compose file as follows:

services:
  hello-world:
    image: hello-world
    environment:
     - test:test
     - test2:test2

Now if I run docker service inspect test_hello-world I see the following in the task template:

"Env": [
    "test:test"
],

Is there a command I can use to get the second environmental variable (test2) added from the compose file?

1

There are 1 answers

1
Ömer Sezer On BEST ANSWER

In short, please run after updating docker-compose to update service: docker stack deploy -c docker-compose.yml test

Explanation:

Please, run docker ps -a after running docker stack deploy -c docker-compose.yml test. You can see that the status of the container is Exited (0). It means that your container is not running at that time.

After docker-compose.yml update with test2:test2 and running docker service inspect test_hello-world, you are not updating your service automatically.

You should run docker stack deploy -c docker-compose.yml test again after docker-compose.yml changes with test2:test2 to update. Then you can see that it was updated. I tested it to be sure that it works like that.

Output:

 "Env": [
      "test2:test2",
      "test:test"
  ], 

You can also test with nginx instead of hello-world.Because it always runs (up). After updating docker-compose, pls run docker stack deploy -c docker-compose.yml test to update.

Terminal:

Updating service test_hello-world (id: m8le589r3cqap8yg3acega0te)

At that time, the previous version was terminated, and a new version was created. docker ps -a shows it.

Terminal (docker ps -a):

CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS              PORTS     NAMES
10a90caaa627   nginx:latest   "/docker-entrypoint.…"   2 seconds ago        Created                       test_hello-world.1.rcrbfttxqw0j22mkw0l149etp
130db6b1d3da   nginx:latest   "/docker-entrypoint.…"   About a minute ago   Up About a minute   80/tcp    test_hello-world.1.hdbj9bjt72sw45obx7h6nga77

docker service inspect test_hello-world
...
"Env": [
   "test2:test2",
   "test:test"
 ],