Find Which Images Docker Compose Services Are Using

Find Which Images Docker Compose Services Are Using

If you need to find out which image a Docker Compose service is using, you need the docker compose images command. In this short tutorial, I’ll show you how it works.

:idseparator: - :idprefix: :experimental: :source-highlighter: rouge :rouge-style: pastie :imagesdir: /images

Recently, I deployed a minor feature change to a small web-based application that was running with Docker Compose. On checking the application post-deployment, however, I was surprised to see that the expected change hadn’t been deployed. Just to be sure, I confirmed that:

. New versions of the relevant Docker images had been built. . The new images had been pushed to the remote Docker container registry. . The application had been re-deployed using docker compose down and docker compose up -d. . The browser’s cache had been cleared.

Given that, I was confused as to why the expected change wasn’t deployed. At this point, I accessed the remote PHP service using docker exec and checked the relevant code. Sure enough, it hadn’t been updated. It seemed that, for some reason, the new images hadn’t been deployed.

The question was though, how could I check which image was being used by the application? I’d not needed to do this before, as deployments had always gone pretty smoothly, so I didn’t know how. Docker being Docker though, I figured that there had to be a command which would tell me what I needed to know.

So, after some searching, I found the docker compose images command. Quoting[the official documentation], this command:

Lists images used by the created containers.

It prints out a list of images used by the currently running containers, along with details, such as the image’s tag, id, and size. On running it from the directory where the application’s Docker Compose configuration files were located, I saw output similar to the example below.

Container                         Repository                    Tag                 Image Id            Size
linkedin-post-scheduler-email-1   mailhog/mailhog               v1.0.1              4de68494cd0d        392MB
linkedin-post-scheduler-nginx-1   nginx                         1.21.6-alpine       51696c87e77e        23.4MB
linkedin-post-scheduler-php-1     linkedin-post-scheduler_php   latest              447fe0e7ab6d        258MB

It was then that I saw in the Tag column, that the php container was still using the previous version of the image. After further investigation, it turned out that I had changed[the Docker Context], for some reason, between building and pushing the images, from the remote to the local Docker daemon.

After changing it back to the remote Docker daemon, pushing the applicable images, and redeploying the application, the functionality was working as expected.

So, if you need to find out which images Docker Compose containers are using, use[the docker compose images command]. Oh, and check that you’re using the correct Docker Context before redeploying the application.

While it was a frustrating experience, it’s also encouraged me to use a CI/CD tool, regardless of how small an application is (wherever practical).

[.img-nopadding] image::books-and-courses/deploy-with-docker-compose/promo-banner-small.png[link=“”]

Do you need to get your head around Docker Compose quickly?

What about needing to dockerize existing applications to make them easier to deploy, reducing the time required for develwpers to get started on projects, or learning how to debug an existing Docker Compose-based app? Then this free book is for you!

You might also be interested in these tutorials too...

How to Deploy a PHP App to Production With Docker Compose
Sun, Nov 12, 2023

How to Deploy a PHP App to Production With Docker Compose

Want to know how to deploy a PHP app to production (or any other remote environment)? In this tutorial, I’ll show you all the steps involved, and provide background information along the way, so you can build on what you’ll learn.

How to Test PHP Apps Running in Docker Containers
Sat, Nov 11, 2023

How to Test PHP Apps Running in Docker Containers

Docker and Docker Compose simplify setting up local development environments for developing PHP apps and for deploying them, whether locally or remotely. But, when your PHP app is running inside a Docker container, how do you run your tests — especially test suites that depend on resources such as database or caching servers? In this tutorial, I’ll show you how to do so.

Override an Image's Command with Docker Compose
Thu, Oct 26, 2023

Override an Image's Command with Docker Compose

Sometimes, you need to override an image’s command when launching a container with Docker Compose. If you need to do that, in this tutorial I’m going to show you how — without the need to update an image’s Dockerfile or shell scripts.

Want more tutorials like this?

If so, enter your email address in the field below and click subscribe.

You can unsubscribe at any time by clicking the link in the footer of the emails you'll receive. Here's my privacy policy, if you'd like to know more. I use Mailchimp to send emails. You can learn more about their privacy practices here.

Join the discussion

comments powered by Disqus