- [Narrator] Whether you deployed
your application in a container
managed by a service or as a service managed by a stack,
at some point, it's likely that
you're going to want to modify
the network ports that are being exposed
to those containers and those applications running inside.
Now, the command that you use to do that is
docker service update to update the service.
Unless, you deployed that service inside a stack.
In that case, you would want to edit
the stack file and then redeploy the stack
to update the stack that's already running.
And modify the network ports that are being exposed.
If we do a docker service ls,
we can see that we have the web app one service
and mystack web service.
So, let's do docker service ps on mystack web.
And you can see there are many replicas,
looks like 30 replicas running.
Now, if we want to modify the network
ports that are being published,
we can use the docker service update command.
Now, if you're unclear on exactly what commands to use
when it comes to modifying specific ports,
I recommend the docker documentation.
Back here, we can go down and take a look
at the published option right here.
Publish add and publish rm to remove.
In our case, we'll want to use
dash dash public dash add to add or update a published port.
If we scroll down, there is a command sample down here
of how you would reconfigure network ports.
For example, right here to add or remove published ports,
use the dash dash public dash add flag,
just like they do in this example.
So, let's give that a try.
We'll do a docker service update.
We'll do dash dash publish dash add.
And from here, we can do published equals 8080 comma
target equals 8080.
And then after that, you would
enter the name of your service.
In this case, mystack web.
Alright, it looks like our published ports were modified.
And if we do a docker service inspect
on mystack web and grep for 8080,
we can see the target port and
published port has been added because
I know those were not there before.
So, that's how you use docker service update
to modify the networking on a running service.