Click here to Skip to main content
15,946,342 members
Articles / Artificial Intelligence
Article

How to Run CodeProject.AI Server in Docker

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
8 Nov 2023CPOL6 min read 18.1K   8   9
In this article, I guide you through installing Docker, then running CodeProject.AI Server in Docker.
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.

Image 1

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

Image 2

The first step is to go Getting Started with Docker. Scroll down and click Download for Windows.

Image 3

This downloads Docker Desktop Installer.exe. Double-click the file and the installer runs. When the installer finishes, click Close and restart.

Image 4

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

Image 5

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.

  1. Virtual Machine Platform
  2. Windows Subsystem for Linux
  3. Virtualization enabled in the BIOS
  4. Hypervisor enabled at Windows startup

1. Virtual Machine Platform

Image 6

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.

Image 7

Ensure that Virtual Machine Platform and Windows Subsystem for Linux are checked off.

2. Windows Subsystem for Linux

Image 8

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.

Image 9

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.

Image 10

Double-click wsl_update_x64.msi and Windows Subsystem for Linux Update installs. Restart the computer.

Image 11

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:

PowerShell
wsl --install

3. Virtualization Enabled in the BIOS

Image 12

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:

Image 13

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.

Image 14

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:

BAT
docker pull codeproject/ai-server:latest

To use the GPU enabled version, use:

BAT
docker pull codeproject/ai-server:gpu

Then the image begins to pull:

Image 15

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.

Image 16

Go to Docker in the system tray and right-click on the icon. Select Restart.

Image 17

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.

Image 18

To launch the container, click the play button. Then a dialog appears to offer Optional Settings.

Image 19

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.

Image 20

Click the link under the Ports heading to open the dashboard.

Image 21

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:

BAT
netstat -aon | findstr 32168

Image 22

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:

BAT
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.

Image 23

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.

This article is part of the series 'CodeProject.AI View All

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Writer CodeProject
Canada Canada
Sean Ewington is the Content Manager for CodeProject.

His background in programming is primarily C++ and HTML, but has experience in other, "unsavoury" languages.

He loves movies, and likes to say inconceivable often, even if it does not mean what he thinks it means.

Comments and Discussions

 
QuestionHow to update Pin
Arnie Singh1-Feb-24 2:02
Arnie Singh1-Feb-24 2:02 
QuestionUpdating the image inside of docker? Pin
Tom Carmichael9-Nov-23 21:34
Tom Carmichael9-Nov-23 21:34 
AnswerRe: Updating the image inside of docker? Pin
Sean Ewington23-Nov-23 10:01
staffSean Ewington23-Nov-23 10:01 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA8-Nov-23 14:11
professionalȘtefan-Mihai MOGA8-Nov-23 14:11 
QuestionAny difference in Performance Pin
Lawrence Chow25-Nov-22 6:59
Lawrence Chow25-Nov-22 6:59 
AnswerRe: Any difference in Performance Pin
Sean Ewington27-Nov-22 3:54
staffSean Ewington27-Nov-22 3:54 
SuggestionAdd a note that it doesn't work with old docker v19 Pin
DimitrySTD22-Nov-22 5:27
DimitrySTD22-Nov-22 5:27 
QuestionVery helpful Pin
peterkmx19-Nov-22 13:49
professionalpeterkmx19-Nov-22 13:49 
AnswerRe: Very helpful Pin
Sean Ewington20-Nov-22 2:07
staffSean Ewington20-Nov-22 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.