yeiei.net

Continuous Integration, QA, Docker,...

Running Delphi Applications on Linux with Docker

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.

Update!: If you are using 10.3.3 (Rio) read How to run Delphi apps on Docker Linux with RadStudio 10.3.3

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.

3 Comments

  1. Hi,
    Do you know why we can’t debug a project with Docker? what elements are missing in the conainer?
    Thanks

  2. Hi,

    Do you know why it is impossible to debug a projetct in a Docker container? what elements are missing?
    Thanks.

    I’m using:
    Delphi 10.3 Rio
    Ubuntu 18.04
    PAServer-20.0 (Version 11.0.11.8)
    Docker Version 18.09.1

  3. Hi – this is fab – I have been setting up a docker image and couldn’t work out for the life of me why it wasn’t connecting. Found this totally by accident – I was connected to container IP address not host – Doh!

Leave a Reply

© 2024 yeiei.net

Theme by Anders NorenUp ↑

Si continuas utilizando este sitio aceptas el uso de cookies. más información

Los ajustes de cookies de esta web están configurados para "permitir cookies" y así ofrecerte la mejor experiencia de navegación posible. Si sigues utilizando esta web sin cambiar tus ajustes de cookies o haces clic en "Aceptar" estarás dando tu consentimiento a esto.

Cerrar