How to use docker desktop engine use command to switch container types

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will learn how to use the docker desktop engine use command to switch between container types. You will begin by understanding the purpose of the Docker engine and how to check the current container type.

Following that, you will explore how to switch to Windows containers (on Windows systems) and then switch back to Linux containers. This lab will provide hands-on experience with managing container environments using the Docker CLI.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/ImageOperationsGroup(["Image Operations"]) docker(("Docker")) -.-> docker/SystemManagementGroup(["System Management"]) docker(("Docker")) -.-> docker/ContainerOperationsGroup(["Container Operations"]) docker/ContainerOperationsGroup -.-> docker/run("Run a Container") docker/ImageOperationsGroup -.-> docker/pull("Pull Image from Repository") docker/SystemManagementGroup -.-> docker/info("Display System-Wide Information") subgraph Lab Skills docker/run -.-> lab-555142{{"How to use docker desktop engine use command to switch container types"}} docker/pull -.-> lab-555142{{"How to use docker desktop engine use command to switch container types"}} docker/info -.-> lab-555142{{"How to use docker desktop engine use command to switch container types"}} end

Understand the purpose of docker desktop engine use

In this step, we will understand the purpose of the Docker engine. Docker is a platform that allows you to automate the deployment, scaling, and management of applications using containerization. A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

The Docker engine is the core component of Docker. It is a client-server application with these major components:

  • A server which is a type of long-running program called a daemon process (the dockerd command).
  • A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do.
  • A command line interface (CLI) client (the docker command).

The CLI uses the REST API to control the Docker daemon through scripting or direct CLI commands. Many other Docker applications use the underlying API and CLI.

In the LabEx environment, the Docker engine is already installed and running. You can verify this by running the docker info command. This command displays system-wide information regarding the Docker installation.

docker info

You should see output similar to this, showing details about the Docker version, storage driver, and other information.

Client:
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.9
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:01:17 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.9
  Git commit:       305620d
  Built:            Tue Oct 25 17:59:50 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.10
  GitCommit:        b34a5c8e5367b9d7e345e9371193898cdce23f40
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
 ... (more output)

This output confirms that the Docker engine is running and provides details about its configuration. Understanding the Docker engine is the first step in working with containers.

Check the current container type

In this step, we will check the current container type supported by the Docker engine in the LabEx environment. Docker can run different types of containers depending on the underlying operating system. On Linux, Docker primarily runs Linux containers. On Windows, Docker Desktop allows switching between Linux containers and Windows containers.

In the LabEx environment, you are running on a Linux virtual machine. Therefore, the Docker engine is configured to run Linux containers. You can confirm this by examining the output of the docker info command again. Look for the OSType field.

docker info

In the output, you should see a line similar to this:

OSType: linux

This indicates that the Docker engine is currently configured to run Linux containers. This is the default and expected behavior on a Linux system.

To further illustrate, let's try to run a simple Linux container. We will use the hello-world image, which is a very small image that simply prints a message and exits. First, we need to pull the image to our local machine.

docker pull hello-world

You should see output indicating that the image is being pulled and downloaded.

Using default tag: latest
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:f5233545e4356188889a389e18b407cd9f61f46056b1e172b338cd91f09e9e4c
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

Now, run the container using the docker run command.

docker run hello-world

You should see output similar to this, which is the message printed by the hello-world container.

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub
    (assuming it was not already locally available).
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

This confirms that you can successfully run Linux containers in this environment.

Switch to Windows containers (Windows only)

In this step, we will discuss switching to Windows containers. Please note that this step is only applicable if you are running Docker Desktop on a Windows operating system. The LabEx environment is a Linux virtual machine, so you cannot actually perform this switch here. However, understanding the concept is important if you work with Docker on Windows.

On Windows, Docker Desktop runs a small Linux virtual machine by default to host the Docker engine and run Linux containers. This is because the core Docker engine was originally designed for Linux. However, Windows also supports running native Windows containers.

If you were on a Windows machine with Docker Desktop installed, you would typically switch to Windows containers by right-clicking the Docker icon in the system tray and selecting "Switch to Windows containers". This action would reconfigure the Docker daemon to use the Windows container runtime instead of the Linux VM.

Once switched to Windows containers, you would then be able to pull and run images built for Windows, such as mcr.microsoft.com/windows/nanoserver.

For example, on a Windows machine after switching, you could run:

docker pull mcr.microsoft.com/windows/nanoserver
docker run mcr.microsoft.com/windows/nanoserver cmd /c echo Hello from Windows Container!

The output would be:

Hello from Windows Container!

Since you are in a Linux environment, attempting to pull or run Windows container images will fail. The Docker engine in this Linux VM is not capable of running Windows containers.

Let's demonstrate this by trying to pull a Windows image.

docker pull mcr.microsoft.com/windows/nanoserver

You will likely see an error message indicating that the image is not found or cannot be pulled, as the Docker daemon is looking for a Linux image with that name.

Using default tag: latest
Error response from daemon: manifest for mcr.microsoft.com/windows/nanoserver:latest not found: manifest unknown: manifest unknown

This confirms that the current environment is set up for Linux containers and cannot run Windows containers.

Therefore, there are no practical commands to execute in this LabEx environment for switching to Windows containers. This step serves as conceptual information for users who might work with Docker on Windows.

Switch back to Linux containers (Windows only)

In this step, we will discuss switching back to Linux containers. Similar to the previous step, this is only relevant if you are using Docker Desktop on a Windows operating system. In the LabEx Linux environment, you are already using Linux containers, so there is no action required to switch back.

On a Windows machine where you have previously switched to Windows containers, you would switch back to Linux containers by right-clicking the Docker icon in the system tray and selecting "Switch to Linux containers". This action would stop the Windows container runtime and restart the Linux virtual machine that hosts the Docker engine for Linux containers.

After switching back to Linux containers on a Windows machine, you would again be able to pull and run Linux container images, such as the ubuntu image.

For example, on a Windows machine after switching back, you could run:

docker pull ubuntu
docker run ubuntu echo Hello from Linux Container!

The output would be:

Hello from Linux Container!

Since you are in a Linux environment, you are already using Linux containers. You can confirm this again by checking the OSType in the docker info output.

docker info

As seen in Step 2, the output will show:

OSType: linux

This confirms that the Docker engine in this LabEx environment is configured to run Linux containers, and no action is needed to switch back.

Therefore, there are no practical commands to execute in this LabEx environment for switching back to Linux containers. This step, like the previous one, provides conceptual information for users who might work with Docker on Windows.

Summary

In this lab, we began by understanding the purpose of the Docker engine, which is the core component of the Docker platform for containerization. We learned that the Docker engine consists of a daemon process, a REST API, and a command line interface (CLI). We verified the Docker installation and its running status using the docker info command, which provided detailed system-wide information about the Docker environment.

Following the initial understanding, we proceeded to check the current container type being used by the Docker engine. For Windows users, the lab then guided us through the process of switching the container type to Windows containers and subsequently switching back to Linux containers, demonstrating how to manage different container environments within Docker Desktop.