Run the Caddy web server on Windows Server
Caddy is a web server designed around security. It’s the only web server that uses HTTPS by default and works quite well. If you’d like to use it on Windows, you can. Here’s how to get the Caddy web server working on Windows Server.
How to install Docker on Windows Server
You will need to configure and set up Docker on Windows Server to use the Caddy web server container. Setting up Docker is quite an involved process and has several steps.
To set up Docker on your Windows Server system, open PowerShell and enter the following commands. These commands should install Docker for your usage. However, understand that this version of Docker can only run Windows containers, not Linux ones.
Install-Module -Name DockerMsftProvider ` -Repository PSGallery ` -Force Install-Package -Name docker ` -ProviderName DockerMsftProvider Restart-Computer -Force
For more information on how to get Docker working on your Windows Server, please check out our in-depth guide on how to run Docker containers on Windows Server. It is in-depth and covers everything you need to know about Docker on the Windows server platform.
How to set up the Caddy Docker container on Windows Server
You must pull the latest Caddy Docker container from the Docker hub to run it on your Windows system. To pull it, use the following docker pull command.
docker run -d -p 8100:80 caddy
Pulling the Caddy container will take a bit of time. It has a lot of files to download, so it could take a couple of minutes to complete. When the container is finished being pulled, you can check it with the docker ps -a command.
docker ps -a
Setting up Caddy with Docker Compose
The default setup for Caddy in Docker is more than adequate for most users. However, if you’re an expert, you may wish to have your Caddy server pre-configured with Docker Compose. You must first install and configure Docker Compose on Windows Server beforehand.
To start, open up Windows File Explorer, then, navigate to “C:\Program Files\Docker”. After navigating there, hold down the Shift key, and right-click on a space. Then, select “Open PowerShell window here.”
When you select “Open PowerShell window here,” a PowerShell terminal will launch. From there, enter the following commands. Alternatively, you can run cd 'C:\Program Files\Docker'
in PowerShell.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest "https://github.com/docker/compose/releases/download/v2.11.2/docker-compose-windows-x86_64.exe" -UseBasicParsing -OutFile docker-compose.exe
After downloading the Docker Compose EXE file, you can run it with:
cd 'C:\Program Files\Docker' .\docker-compose.exe
Once you’ve got Docker Compose working, head to the Caddy page on DockerHub and learn how to configure it.
How to use the Caddy web server on Windows Server
Your Caddy image pulled from Docker (the Windows Server edition) comes with a ready-to-run configuration. This configuration doesn’t need to be modified. However, if you wish to make modifications, check out the official Caddy page on DockerHub.
The Caddy image will be running as soon as it is pulled from the Dockerhub. However, you should stop it, as it is still in its “first run phase.” To stop the container, open up Powershell, and execute the following commands.
docker ps -a
Find the Caddy container ID. Then, run docker stop to stop the container from running on your Windows server.
docker stop CONTAINER_ID
With the container stopped, you can start it once again. To start the container, use the docker start command along with the container ID. Do not use “caddy.” Using “caddy” is only applicable when pulling the docker image down for the first time.
docker start CONTAINER_ID
With the container started, you will be able to access the Caddy web server in a browser on your Windows Server (or remotely via the Windows Server IP.) To check that it is working, point your web browser to the following URL.
localhost:8100
Or
windows-server-ip:8100
Using Caddy Web Server
Caddy Web Server is quite advanced, and we won’t be going over how you can customize it for your own needs in this guide. This guide focuses on how to deploy the Caddy web server on a Windows Server system.
However, if you’re new to Caddy, that’s OK. The project has some excellent documentation on how to customize Caddy for your needs, how to serve web pages, activate SSL certificates, and much more.
For more information on the Caddy web server, and what you can do with it on Windows, please check the official documentation. For specific Docker help, check out the Caddy docker page.