- Prerequisites
- Pulling images into Docker Desktop
- Viewing vulnerabilities for images
- Running containers with Docker Desktop
- Investigating containers
- Running commands in the container with an integrated terminal
- Performing basic container actions
- Deleting an image
- Managing volumes with Docker Desktop
- Using extensions to improve container management
- Troubleshooting errors with adding extensions
- Conclusion
- Cockpit: GUI administration for Linux - Thu, May 25 2023
- Install and configure Traefik on Docker - Mon, May 8 2023
- Traefik: Reverse proxy for Docker - Thu, Apr 20 2023
In this tutorial, I will teach you how to use Docker Desktop to tame your Docker environment on Windows.
Prerequisites
This tutorial uses Docker Desktop on Windows 10. Install Docker Desktop on Windows if you do not already have it installed. You can also follow along with Docker Desktop on Linux or macOS.
Pulling images into Docker Desktop
Starting Docker Desktop for the first time (if you haven't done anything with Docker before) opens up a dashboard with no images or containers, as in the screenshot below.
This is normal, as Docker Desktop is primarily meant to assist with managing an existing Docker environment. By implication, Docker Desktop has no native method to pull images from the GUI. You will first have to create some resources with the Docker command line interface (CLI) to have anything to work with in the GUI. And that is exactly what you will do in this section.
Open up a terminal emulator and pull the latest Nginx image.
docker pull nginx:latest
Your screen should be filled with progress reports, as the image is downloaded:
Once complete, it should show up in Docker Desktop under the Images panel, as in the screenshot below:
Viewing vulnerabilities for images
Before running a container, it might be interesting, from a security standpoint, to know what vulnerabilities affect the image you plan to use.
Select the nginx image entry, as in the screenshot below, to get more information.
You should get a count of vulnerabilities according to severity. You can also see the layers and images that make up the Nginx image.
Running containers with Docker Desktop
Click the Run button on the details page to create a container from this image.
Click Run in the popup window that appears, as below.
The Optional Settings menu has been expanded in this screenshot.
This popup window gives you the chance to configure the container with options that are available via the CLI. For example, you can name the container, expose some ports, or attach a volume to it.
Leaving all the fields as they are results in a container with the default configuration.
Investigating containers
Running a container takes you directly to the container details page. On the Logs tab, you will see logs related to the running container, as below.
Select the timestamp button to toggle timestamps on and off. This feature can reduce the effort required to sift through while troubleshooting container issues.
Here is the same view with timestamps enabled, for comparison.
Under the Inspect tab, you can view details about the container's internal environment. As you can see in the screenshot below, the Inspect tab gives you access to the environment variables from Docker Desktop.
Running commands in the container with an integrated terminal
Docker Desktop comes with an integrated terminal that allows you to run commands within the container directly from the GUI. This is like running the "docker exec" CLI command with interactivity.
Switch to the Terminal Tab and get a container command prompt.
You can confirm both the ability to run commands and the fact that the commands are run within the container by executing the hostname command:
hostname
As you can see from the screenshot below, the hostname returned is the hostname of the container, not the Windows host machine.
Performing basic container actions
Head back to the Container panel. There is more you can do with containers in Docker Desktop. In this section, you will learn to control running containers with Docker Desktop.
Pausing a Container
To pause a running container, select Pause from the More Options menu under Actions. Pausing a container saves its state in memory and frees up CPU resources.
You can resume the container by clicking Start in the Actions column. Notice how the status changed from Running to Paused in the screenshot below, confirming the change.
Restarting a container
You can also restart a running container directly by selecting Restart from the More Options menu under the Actions column.
Stopping a container
Once done with a container, you can stop it from the Actions column by clicking the stop icon.
Deleting a container
You can also delete a container altogether by clicking the delete icon, as shown below.
Deleting an image
Now that there are no containers using the nginx image, you can delete it by going to the Images panel. Deleting images allows you to reclaim storage space for other uses.
Confirm that the image is not being used by checking the Status column. It should read Unused, as in the screenshot below.
Click the Delete icon to delete the image. It is important to note that images cannot be deleted if they are being used by a container. Confirm your choice in the popup that will follow.
Managing volumes with Docker Desktop
Volumes are another resource Docker Desktop allows us to manage. Unlike images, you can create volumes directly from Docker Desktop, as well as manage those created with the CLI.
Open the Volumes panel, as shown below.
Docker begins with a list of available volumes. Since none has been created yet, it reports an empty list.
Click Create to create a new volume.
Supply an appropriate name, and click Create. This tutorial uses my-vol, but you can use any name you want.
The list of volumes should now have an entry, as shown in the screenshot below. You can also create more volumes and attach them to containers as part of the container creation process. Docker Desktop allows you to view all volumes in your environment along with their sizes.
You can delete unused or unwanted volumes by clicking the Delete icon, as shown below:
Confirm the deletion, as in the following screenshot, to remove the volume.
Using extensions to improve container management
Docker Desktop can be even more useful if you enhance its capabilities with extensions. In this section, you are going to learn to add the Resource usage extension, which gives you a holistic overview of utilization in your environment.
Click Add Extensions to open up the extensions marketplace.
Begin to type in the name of the extension, Resource usage, until the extension comes up for install.
Click Install to add it to your Docker Desktop.
Select Resource usage under Extensions to get a feel for what metrics it collects and displays. If you have no containers, the panel should be empty, as shown in the screenshot below.
Troubleshooting errors with adding extensions
There is a known bug that can come up while you are trying to install new extensions. If you get a notification that "the local image you are trying to install has been modified and is different from the published image," don't fret.
Navigate to the Docker contexts folder at %userprofile%\.docker. The local user account for this tutorial is named "as:"
Delete the contexts folder, restart Docker Desktop, and try adding the extension again.
Conclusion
Congrats! By coming this far, you have learned how to use Docker Desktop to manage images, containers, and volumes. With this knowledge, you can harness the benefits of Docker Desktop to streamline your development or sysadmin workflow.
Subscribe to 4sysops newsletter!
As a next step, you can explore the Extensions marketplace to see what is on offer to ease up your container administration experience.