I use the Play-with-Docker platform to create a Swarm cluster with 3 Docker instances: 1 manager and 2 workers; then I create a service from the image nginx:alpine
:
docker service create -p 8080:80 --name nginx-app nginx:alpine
Things worked fine.
Then I update
the service to change the published port: instead of 8080
, now I want the published port to be 8081
. I ran this:
docker service update --publish-rm 8080 --publish-add 8081 nginx-app
But it did not remove the published port 8080
; instead it created another published port 30002
, this port 30002
mapped to 8081
What did I do wrong here? How can I change the published port?
2
Answers
Remove those services and start it like this instead:
docker service create -p 8081:80 --name nginx-app nginx:alpine
The
--publish-rm
option takes the target port, not the published port: