Articles Getting Started with Delphi and Linux Docker Suppor by Marco Cantu

emailx45

Местный
Регистрация
5 Май 2008
Сообщения
3,571
Реакции
2,439
Credits
574
Getting Started with Delphi and Linux Docker Suppor
[SHOWTOGROUPS=4,20]
Marco Cantu
2/12/2019

Over the last few years, it has become more and more common to deploy server side solutions (and in fact any type of application) to lightweight containers rather than physical machines or virtual machines, as this allows more flexibility (also in terms of testing), a better way to rebuild the same execution environment, and more scalability. Along with the 10.3.3 release, Embarcadero has started officially supporting deployment of general Linux applications to Docker containers, specifically supporting the deployment to RAD Server.
In this blog post I’ll introduce Docker and Docker Hub and how you can easily get started deploying your Linux application to Docker. In a second blog post I’ll focus specifically on RAD Server deployment. We are also going to have a more detailed white paper on this topic available soon.
What is Docker
Docker is an OS-level virtualization environment that allows for the packaging and delivery of software as a bundle inside a container file. The container files are executed by the Docker Engine and multiple containers can run side by side on the same Linux installation. Inside each container is an OS-level virtualization environment.
Containers are more lightweight than virtual machines because they are run by Docker Engine. Containers are created by building a set of instructions called a Dockerfile into a container image. Container images are then executed on the Docker Engine. Both the build step and run step can take a number of arguments that configures that specific build or run container image.
Additionally, existing container images can be used as starting points from within Dockerfiles which allows you to add new functionality on top of the functionality of the existing container image. There are many sources of information on containers and docker, and a good starting point is Для просмотра ссылки Войди или Зарегистрируйся.
What is Docker Hub?
Docker provides a service that allows developers and publishers to distribute Docker images to the public or their team. This service is known as Docker Hub and provides a way for users to use repositories where specific Docker Images are located. Docker repositories also allow for Docker Image versioning. Docker Hub contains official images such as the Ubuntu image that can be used as starting points for many users.
RAD Studio Docker Containers
The RAD Studio Docker containers paserver, pa-radserver, and pa-radserver-ib are available directly from DockerHub and also as Dockerfiles (on GitHub) plus additional helper utilities. When pulling the containers from DockerHub using Docker the organization name has to be prefixed to the container name such as radstudio/paserver, radstudio/pa-radserver, and radstudio/pa-radserver-ib. For this blog post I’ll start focusing on the first one, radstudio/paserver, which does not include RAD Server.
Docker containers have a number of different parameters that you can pass to the Docker Engine when starting an instance. Additionally, custom build and run parameters can be defined when building and running a Docker image. A number of custom parameters have been included in the scripts we provide, including for example the password for PAServer.
Docker container instances can be run in the foreground where you can interact with an app that is running within the instance or they can be run detached in the background which behaves like a service.
Docker container instances will not by default store any changes to the instance between runs (they are transient images). However, you can set up a persistent Volume within the Docker instance which will store changes between runs of the Docker container instance. A directory within the Docker instance can be mounted to the Volume and any changes made within that directory persist on the Volume between runs of the Docker instance.
How To Install Docker on Linux
The Docker system can be installed in a number of ways. One way to install Docker is to use the APT package manager that is included in the Ubuntu operating system. To install Docker using APT simply run the apt install command with elevated privileges either by using sudo or by using the super user account.
#if using sudo
sudo apt install docker.io

#if using super user account
apt install docker.io
The PAServer Docker image
The PAServer Docker image uses Ubuntu:Bionic as a base image and builds on it to include the PAServer tool and its functionalities. The PAServer tool is downloaded from the Embarcadero server. This image contains PAServer and all of its dependencies along with the GTK+ framework for using BroadwayD (a feature part of the FMXLinux library for building UIs on Linux, library that is freely included with the Delphi). BroadwayD can be used to display GTK+ applications on the web via HTML5 and websockets. Having these two tools available on the same Docker container allows for developers to deploy console and GUI based applications using the PAServer and view the GUI applications through a web browser via the BroadwayD server.
This image has a few parameters, including the
  • The PAServer password and can be set as build parameter or run parameter
  • Whether you want to run in foreground interactive mode (-it) or detached mode (-d)
  • The external PAServer port (that is the port of the host mapped to the PAServer port in the container) and the broadwayd port remapping
  • The default password for PAServer is set to ‘embtdocker’
This is an example of how you can download the image and start it with a few parameters:
docker pull radstudio/paserver
docker run -it -e PA_SERVER_PASSWORD=securepass -p 64211:64211 -p 8082:8082 radstudio/paserver

This is is a Linux console (via PuTTY) after the Docker image has been installed:
pastedimage1575285031768v1.png



At this point you can refer to the docker image by its host IP and the port address from the RAD Studio IDE, and deploy and run a Linux application via PAServer hosted by the docker image. Therefore the Delphi application will run under docker.

docker_paserver02.png




The Dockerfile on GitHub
Instead of pulling an image from docker hub, you can create a custom one using the scripts we have built and are making available on GitHub. The PAServer Dockerfile includes the instructions which are used at build time by Docker to create the Docker image. The Dockerfile relies on a specific version of PAServer that is downloaded from Embarcadero and it is available at:
Для просмотра ссылки Войди или Зарегистрируйся
More Coming
In the next blog post, we’ll continue by focusing on RAD Server deployment via docker, which was the key reason for Embarcadero to support docker containers.

[/SHOWTOGROUPS]
 
Последнее редактирование: