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?
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 runningdocker stack deploy -c docker-compose.yml test
. You can see that the status of the container isExited (0)
. It means that your container is not running at that time.After docker-compose.yml update with
test2:test2
and runningdocker service inspect test_hello-world
, you are not updating your service automatically.You should run
docker stack deploy -c docker-compose.yml test
again afterdocker-compose.yml
changes withtest2:test2
to update. Then you can see that it was updated. I tested it to be sure that it works like that.Output:
You can also test with
nginx
instead ofhello-world
.Because it always runs (up). After updating docker-compose, pls rundocker stack deploy -c docker-compose.yml test
to update.Terminal:
At that time, the previous version was terminated, and a new version was created.
docker ps -a
shows it.Terminal (docker ps -a):