How to run Docker containers on Windows Server
Docker is a powerful containerization program for Windows, Linux, and BSD server systems. With Docker, you can deploy a wide variety of apps that are self-contained, like Plex, NextCloud, PhotoPrism, Nginx, etc. Here’s how to run Docker containers on Windows Server.
How to install Docker on Windows Server
To use the command-line version of Docker on your Windows Server, you will need to install it via the PowerShell tool. Open up Powershell on your Windows Server as Administrator.
Once the Powershell application is open, use the Install-Module command. This command will enable the “PSGallery” Powershell Gallery software repository on your Windows Server.
Install-Module -Name DockerMsftProvider ` -Repository PSGallery ` -Force
Windows will ask you to import the “NuGet” provider with the module command above run. Select “Y” on the keyboard to import it. Then, run the Install-Package command below to install the “docker” package on your server.
Install-Package -Name docker ` -ProviderName DockerMsftProvider
After entering the command above, Powershell will say, “The package(s) come from a package source that is not marked as trusted. Are you sure you want to install software from “DockerDefault”?
Press the Y key on the keyboard to tell Windows Server that you trust this software source and wish to install Docker via Powershell. Then, once the Powershell tool finishes installing the “docker” package, you must reboot Windows Server. You can reboot it with the command below.
Restart-Computer -Force
Upon rebooting, log back into your server. Then, re-launch Powershell and use the Get-WindowsFeature command to verify that you have Docker enabled. Assuming you do, you’ll see [X] Containers
.
To learn more about Docker, run the docker –help command in the Powershell application. Doing this will show you Docker’s “help” section. This section will go over everything you need to know about the Docker tool and how to use its commands.
docker --help
How to verify that Docker is working
To verify that the Docker application is working correctly on your Windows Server, you must download the “hello-world” container and run it. To download “hello-world,” ensure you have Powershell open. Then, use the following command.
docker pull hello-world
If you can “pull” the “hello-world” container, Docker should run fine on your Windows server. To run the “hello-world” container, run the following docker run command.
docker run hello-world
Assuming the command above is successful, you should see the following message:
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.
(windows-amd64, nanoserver-ltsc2022)
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.
How to download Docker containers on Windows Server
To run a Docker container on your Windows Server, you must first pull one from Dockerhub. Head over to Dockerhub, and search for a container you’d wish to run on your server. however, keep in mind that you will only be able to use Windows containers, not Linux ones.
Note: If you wish to use Linux containers on Windows Server, it is possible. However, you will need to install Docker for Windows instead of the Enterprise version of Docker covered in this guide.
Once you’ve located the image, read the page for the official instructions on how to run it. Then, open up a Powershell window. Then, pull down your docker image to the system using the docker pull command.
docker pull windows-docker-container
How to run Docker containers on Windows Server
To run a Docker container on your Windows Server, start by running the docker ps -a command in Powershell. This command will list all containers on your system, even ones not running.
docker ps -a
After executing the docker ps -a command, Docker will show you all containers. Find the ID of the container you wish to run on Windows Server. Then, run the docker run command.
docker run CONTAINER_ID
Once the command above is run, your Docker container will be running on Windows Server. To shut down this container, you can run the docker stop command.
docker stop CONTAINER_ID
How to delete Docker containers on Windows Server
You may want to delete a Docker container from your Windows Server system at some point. To do that, do the following. First, open Powershell. Then, run the docker ps -a command to list all containers.
docker ps -a
After listing all containers, use the docker rm command to delete the container from your Windows Server system.
docker rm CONTAINER_ID