This is a step-by-step guide to installing Docker, running CodeProject.AI Server in Docker, and troubleshooting conflicts with running it as a Windows Service.
The Quick Answer
In a nutshell:
docker run codeproject/ai-server
For all the various flavours of docker images we support, and the flags needed for each, please refer to the CodeProject.AI docs.
The Longer, More Helpful Explanation
This packs in a fair amount for those who are not familiar with Docker, and is only for the CPU version on x86_64 architectures, so let's walk through what this actually means and what other options are available.
In a previous article, I installed CodeProject.AI Server on Windows, so in this article I wanted to see if I could get it running in Docker. I had never used Docker before, so I started from scratch.
Here is a complete walkthrough of installing Docker, then getting CodeProject.AI Server running in Docker.
Installing Docker
The first step is to go Getting Started with Docker. Scroll down and click Download for Windows.
This downloads Docker Desktop Installer.exe. Double-click the file and the installer runs. When the installer finishes, click Close and restart.
Once the computer is done restarting, the Docker Subscription Service Agreement launches. Click Accept. In most cases, that's it. Docker is installed!
An Unexpected Error Occurred with Docker
At this stage, I got an error as shown above. The error provided a link for more help, but the link that actually helped me though was Troubleshoot topics. Under Virtualization, there is a list of what is required.
- Virtual Machine Platform
- Windows Subsystem for Linux
- Virtualization enabled in the BIOS
- Hypervisor enabled at Windows startup
First, the Virtual Machine Platform must be enabled. To do this, go to the Windows menu and start typing "Turn Windows features on or off". This brings up the Windows Features panel.
Ensure that Virtual Machine Platform and Windows Subsystem for Linux are checked off.
2. Windows Subsystem for Linux
Even though my Windows Subsystem for Linux was checked, I still got an error:
Quote:
WSL 2 installation incomplete. The WSL 2 Linux kernel is now installed using a separate MSI update package. Please click the link and follow the instructions to install the kernel update: https://aka.ms/wsl2kernel. Please Restart after installing the Linux kernel.
To install the MSI package, follow the error's instructions. Go to https://aka.ms/wsl2kernel, click WSL2 Linux kernel update package for x64 machines, which downloads wsl_update_x64.msi.
Double-click wsl_update_x64.msi and Windows Subsystem for Linux Update installs. Restart the computer.
An alternative to this is to use PowerShell. To open the PowerShell terminal, go the Windows menu and begin typing "PowerShell". Then launch the Windows PowerShell app.
Then simply use the command:
wsl --install
3. Virtualization Enabled in the BIOS
While the computer is restarting, enter the BIOS settings. Typically, you do this when the computer is loading from the black screen. Simply press the magic button to enter the BIOS, with the actual button varying from machine to machine. It's either Delete, Esc, F1, F2, or F4. For me, it's Delete or F2.
If you're running Windows 11, you may need to go to Settings and:
- Go to System
- Choose the Recovery card on the right hand panel
- On the Advanced Setup row click Restart now
The machine reboots then potentially offers more hoops to jump through (they really don't want you to mess with those BIOS settings).
Once in the BIOS you'll see something similar to:
From here, look for the CPU configurations. It's either under Processor, Chipset, or Northbridge. Virtualization is either called VT-x, AMD-V, SVM, or Vanderpool. My computer is an older Asus machine, so Virtualization was actually listed as Intel Virtualization Technology, which was formerly known as Vanderpool. Make this enabled, then save changes and exit.
After restarting, Docker launches and is ready to go!
Running the CodeProject.AI Server Docker Image
Note: If you have already installed CodeProject.AI Server as a Windows service, you will need to stop it first. If you don't do this, you will get an error that I address in
Docker vs a Windows Service
Even better: decide whether you wish to run CodeProject.AI Server as a Windows Service or as a Docker container. You can do both, but there's no benefit, just mess.
The first step is to make sure Docker Desktop is running. Actually, you want to ensure the Docker service is running, but Docker Desktop handles this for you.
The second step is to hit the Windows key and type CMD to open the Command Prompt. I want to run the CPU version of CodeProject.AI Server, so I first need to pull the image:
docker pull codeproject/ai-server:latest
To use the GPU enabled version, use:
docker pull codeproject/ai-server:gpu
Then the image begins to pull:
Troubleshooting Pulling a Docker Image
During the installation, Docker got stuck while pulling the image. Looking at the Docker forums, this can be fixed by restarting Docker.
Go to Docker in the system tray and right-click on the icon. Select Restart.
A warning message pops up. The image pull process remembers what has already been downloaded, so hit Restart.
Then go back to the command prompt and reenter the pull command you typed in previously. Docker should pick up right where it left off, and continue pulling the image.
Launching the Docker Container
Once the image has been pulled, it will appear in Docker Desktop.
To launch the container, click the play button. Then a dialog appears to offer Optional Settings.
Give your container a name, set the Host port as 32168, and click Run.
Go to the Containers tab in Docker Desktop to see the container running.
Click the link under the Ports heading to open the dashboard.
That's it! You are now running CodeProject.AI Server from within a Docker container.
Docker Versus a Windows Service
After the CodeProject.AI Server Docker image finished pulling and I tried to start the image, it wasn't the smooth sailing shown above. When I launched the image, I got this error:
Quote:
docker: Error response from daemon: Ports are no available: exposing port TCP 0.0.0.0:32168 -> 0.0.0.0:0: listen tcp 0.0.0.0:32168: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
What was going on?
To troubleshoot what was happening, I needed to figure out what process is using port 32168. I opened the command prompt and typed:
netstat -aon | findstr 32168
From the list, notice TCP [..]32168 [::]:0 LISTENING 10592
. This indicates that process 10592 is using port 32168. But what is process 10592? To find out, type into the command prompt:
tasklist | findstr 10592
The answer: CodeProject.AI Server.exe. You need to stop CodeProject.AI Server beforehand if you wish to use the same port 32168.
If you didn't stop CodeProject.AI Server, open a command terminal.
Start typing "Services" and launch the Services app. Scroll down and look for CodeProject.AI Server, right-click on it, then select Stop. You should now be good to go.
As mentioned previously, you should decide whether you wish to run CodeProject.AI Server in Docker or as a Windows Service. Having both is possible but messy and unnecessary. If you really do wish to run both, just choose a different port number and you'll be fine.