Starting from Rad Studio 10.2 Tokyo it is possible to compile and run Linux server applications (without user interface). We are going to prepare a docker image with Ubuntu and everything necessary to run Delphi applications on Linux, via PAServer. With Docker we may deploy these applications in Linux containers to our production system.

The possibilities are immense, from setting up a universe of interconnected microservices for high availability and fault tolerance to monolithic applications. One of the advantages of using Docker is that we can prepare a base image (much lighter than using virtual machines) and deploy it as we need it.

Let’s do it

The fast path

Open a console where you have Docker installed. In my case I use Docker Toolbox for Windows and start Docker Quickstart Terminal.

docker pull jaruzafa/ubuntupaserver 
docker run -p 64211:64211 -t -i jaruzafa/ubuntupaserver

BOOM! You’ve done it, now go to read RadStudio section below.

The slow path

Our image will be based on Ubuntu 16.04. Create a text file named Dockerfile, with this content:

#Imagen base 
FROM ubuntu

# Everything you need for RadStudio plus some utilities that may come in handy
RUN \
 apt-get -y update && \
 apt-get -y upgrade && \
 apt-get -y dist-upgrade && \
 apt-get -y install joe wget p7zip-full curl unzip build-essential zlib1g-dev libcurl4-gnutls-dev && \
 apt-get -y install mysecureshell && \
 apt-get -y autoremove && \
 apt-get -y autoclean

# Copy PAServer to container and unzip it
COPY LinuxPAServer19.0.tar.gz /root/LinuxPAServer19.0.tar.gz
RUN \
 cd /root && \
 tar xzvf LinuxPAServer19.0.tar.gz && \
 cd PAServer-19.0 && \
 mkdir scratch-dir

# Working directory
WORKDIR /root/PAServer-19.0

# Start PAServer
CMD ["/root/PAServer-19.0/paserver","-password=1234"]

# Publish PAServer default port
EXPOSE 64211

Just remember to copy  C:\Program Files\Embarcadero\RADStudio\19.0\PAServer\LinuxPAServer19.0.tar.gz to the same folder where you have your Dockerfile.

Run Docker Quickstart Terminal and type:

docker build -t mirepo/mimagen .

Now you have your image created. Just start the container:

docker run -p 64211:64211 -t -i mirepo/miimagen

Now the RADStudio side

Hello world….

In Rad Studio click New Project->Console Application

Complete the code:

program Project1;
 {$APPTYPE CONSOLE}
 {$R *.res}

uses
 System.SysUtils;

begin
 try
   Writeln('Hello world Docker/Linux ');
 except
 on E: Exception do
   Writeln(E.ClassName, ': ', E.Message);
 end;
end.

In the Project Manager, right click to add the Linux platform:

Select Linux-64bit:

It will ask for the profile name:

I wrote “paserverxubuntu”, but you can write the name you want.

Now comes the tricky part, you will be asked for the IP where PAServer is listening. You must type the IP of the Docker host, not the container’s IP!

In my case, I use Docker Toolbox for Windows, the IP is 192.168.99.100.

 

Default port is 64211 and password is “1234”:

CLick “Run”  (the first time it will copy the SDK, this may take some minutes)

At Docker container you’ll see:

And that’s it!

Note: The Docker image in this example is suitable for deploying applications, but you will NOT be able to debug (breakpoints and stuff, you know …), since it does not contain everything necessary for the RadStudio debugger to work.