Docker Roadblocks: Things to Know

This is just a use case providing some ways in which you might want to review your docker containers. I provide some basic considerations in dealing with Docker Compose.

I like to install each of my docker applications in a dedicated LXD container. I do this for managability. Since I present my LXD containers on my LAN with LAN addresses, each of my nested docker compose apps its own dedicated address. This avoids port conflicts having to juggle port numbers.

In the video, I review a docker compose file for Rocketchat and I use this application as a use case for common docker issues. This is not a tutorial on Rocketchat. I have a separate video on new Rocketchat installation and another on Rocketchat upgrade. That being said, this video was about docker commands.

Any given docker compose file may have more than one container to support an application. To list all of the containers that are running from a given docker compose file you should be in the folder where the docker compose file is located and then issue this command:

docker compose ps

Notice in the command above that I did not put a “-” dash between the word docker and the word compose. “docker compose” is version 2 of docker compose which was released in June 2021. The docker-compose command still exists in the newer “docker compose”, however it will be deprecated at some point. Notice the difference in the two commands above.

Another example of the “docker compose ps” command:

The way to list all running docker containers on a docker host:

docker ls

Images are used to create containers and you may have older images still on your docker host.

In my example of upgrading rocketchat, we upgrade only the rocketchat container and not the database. Since the rocketchat “tag” in the docker compose file is “latest”, a "pull command will download a newer version of just the rocketchat container. By stopping and deleting that container, I remove the old image which is no longer needed.

docker pull rocketchat/rocket.chat:latest
docker compose stop rocketchat
docker compose rm rocketchat
docker compose up -d rocketchat

It is possible to remove “orphaned” or unused containers, images and even volumes on a docker system. You should be very cautious with this dangerous command. This might be another reason why having a docker application on a dedicated lxd container would be a good way to protect other apps from dangerous commands:

docker system prune -a --volumes

image

After the prune is completed, the system is cleaned up (be sure to do a snapshot of the docker host before the prune for safety):

Containers can be controlled by knowing their ID’s and this command lists the ID’s of the running containers:

docker ps -aq

Knowing this, you can stop all running containers on a docker host:

docker stop $(docker ps -aq)

Another dangerous command can remove all containers:

docker rm $(docker ps -aq)

You can also remove all images. I have to confess that I sometimes use this command to clean up old images since it will not delete any image that is being used by a container that happens to be running:

docker rmi $(docker images -q)

The important things to know for a docker application are:

  1. The version number of each container image you are running.
  2. The version number referenced in your docker-compose file.
  3. The data in your non-volatile volumes on the docker host for the application and which container image wrote it.
  4. The images and versions currently downloaded on the docker host both used and unused.
  5. You should understand if your images are downloaded from a repository or created with a “docker build” command.

These are just a few of the considerations when maintaining docker applications. Hopefully some of these commands will help.

1 Like