Running Delphi Applications on Linux with Docker by Jarufaza

emailx45

Местный
Регистрация
5 Май 2008
Сообщения
3,571
Реакции
2,438
Credits
573
Running Delphi Applications on Linux with Docker
24/05/2017 - JARUZAFA
[SHOWTOGROUPS=4,20]
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 Для просмотра ссылки Войди или Зарегистрируйся

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
Код:
[QUOTE]Hello world….[/QUOTE]
[QUOTE]
[/QUOTE]
In Rad Studio click New Project->Console Application

2017-04-29-13_29_12-IE11-Win7-Configurada-antes-de-arrancar-Corriendo-Oracle-VM-VirtualBox.png


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:

2017-04-29-13_31_02-IE11-Win7-Configurada-antes-de-arrancar-Corriendo-Oracle-VM-VirtualBox.png


Select Linux-64bit:

2017-04-29-13_31_18-IE11-Win7-Configurada-antes-de-arrancar-Corriendo-Oracle-VM-VirtualBox.png


It will ask for the profile name:

2017-04-29-13_32_02-IE11-Win7-Configurada-antes-de-arrancar-Corriendo-Oracle-VM-VirtualBox.png


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

2017-04-29-22_16_41-IE11-Win7-Configurada-antes-de-arrancar-Corriendo-Oracle-VM-VirtualBox.png


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.

IPDocker.png


Default port is 64211 and password is “1234”:

2017-04-29-22_32_56-IE11-Win7-Configurada-antes-de-arrancar-Corriendo-Oracle-VM-VirtualBox.png


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

2017-04-29-22_33_56-IE11-Win7-Configurada-antes-de-arrancar-Corriendo-Oracle-VM-VirtualBox.png


2017-04-29-22_34_29-IE11-Win7-Configurada-antes-de-arrancar-Corriendo-Oracle-VM-VirtualBox.png


At Docker container you’ll see:

2017-04-29-22_43_48-IE11-Win7-Configurada-antes-de-arrancar-Corriendo-Oracle-VM-VirtualBox.png


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.

[/SHOWTOGROUPS]