loading...

Docker – The rest of the stack commands

How to configure WordPress multisite with NGINX

Now, let’s take a quick look at our other stack-related commands through the lens of the swarm where we deployed our voteapp¬†stack. First up, we have the list stacks command: docker stack ls. Giving that a try looks like this:

# List the stacks deployed in a swarm
docker stack ls

Here is what it looks like in the example environment:

This is showing that we have one stack named voteapp currently deployed, and that it is composed of six services and is using swarm mode for its orchestration. Knowing the name of a deploy stack allows us to gather more information about it using the other stack commands. Next up is the list stack tasks command. Let’s give this command a try in our example environment:

# List the tasks for our voteapp stack filtered by desried state
docker stack ps voteapp --filter desired-state=running

Here are the results in my environment right now; yours should look very similar:

Now, we will have a look at the stack services command. This command will give us a nice summary of the services that are deployed as part of our stack application. The command looks like this:

# Look at the services associated with a deployed stack
docker stack services voteapp

This is what we see in the example environment:

This command provides some very useful information. We can quickly see the names of our services, the number of replicas desired, and the actual number of replicas for each service. We can see the image used to deploy each service, and we can see the port mapping used for each service. Here, we can see the visualizer service is using port 8080, as we mentioned earlier. We can also see that our vote service is exposed on port 5000 of our swarm hosts. Let’s have a look at what we are presenting in our voteapp by browsing to port 5000 (on any node in the swarm) now:

Are you a dog person or a cat person? You can express yourself by voting in your own voteapp! Cast your vote and then use the data in the stack service command to see the results of the vote by browsing to port 5001:

Yes, I am a dog person. There is one final stack command: the remove command. We can quickly and easily take down an application deployed with the stack deploy command by issuing the rm command. Here is what that looks like:

# Remove a deploy stack using the rm command
docker stack rm voteapp

Now you see it, now you don’t:

You should notice that there was none of the are you sure? hand-holding, so be very sure and very careful before pressing Enter on this command. Let’s close out the discussion on Docker stacks with a quick look at the best practices for scaling or restacking an application deployed as a Docker stack.

Comments are closed.

loading...