- [Lecturer] It's bound to happen.
Sooner or later you could have trouble
starting or running services in Docker swarm.
Let me give you a few tips of what I
recommend you do if you experience
some sort of trouble with services.
The first thing I encourage you to check out
are the Docker service logs.
We're looking here at the main page or the documentation
for the Docker service logs command
and as you can see there are a number of command line
options or flags that can be used with it.
Let's go over into Docker and let's try out
Docker service logs.
So if we type docker service, space logs,
it tells us that there are some options we can enter
and the primary argument that we need to provide
is the service or task.
So if we do a docker service ls,
you can see we already have a number of services running
but I really want to start up a brand new web server
that we can interact with.
So let's do a docker service create.
We'll do a --name, and we'll call it webserver2.
We'll map ports 8080 on the outside to 80
inside the web server.
We're not going to specify the number of replicas,
we'll just assume we'll have a single web server
task running inside this service.
And then finally we'll provide httpd for the imaged name.
So we started our new web server service.
If we do a Docker service ls,
you can see the web server service is running there.
And it's on port 80, 80.
So let's go open our web browser
and let's test the web server.
Here's the IP address, 10.35.3.100:8080
and we get the message there that it works.
So that's great, it's a great test.
If we go back to the command line here,
I want to use now docker service logs.
So docker service logs require that we give it
the service name, in this case it's webserver2.
And here we get the output of what the logs look like.
And one of the cool things you can do
is docker service logs -f,
and that'll give you a constant real time update
of what's going on with this web server service.
If we go back to our web browser
and push refresh again, then go back to Docker,
you can see we have a new entry here in the log.
So let's try it again.
I'm going to do a refresh, go back again,
there we go, we got some new entries in the log.
So we're watching real time what's going on
with this web server, and in my experience
this is a very valuable tool in helping us
to troubleshoot any sort of service issues
inside Docker swarm.
In my opinion, the docker service logs command
is very helpful when it comes to
troubleshooting a service in Docker swarm.