Table of contents

Official Content

Use the steps described in this article to easily deploy and run Java, .NET Framework and .NET generated applications in a Docker Container.

Note that these steps help you to deploy the generated programs, not the database. To deploy the database, see Export Reorganization. For further options, see Application Deployment tool.

Software Requirements:

Steps to deploy to Docker

1. Before you deploy your application for the first time to a specific target (e.g., production), creating a new environment in the Knowledge Base is recommended, so that it:

  • Runs locally in the Tomcat or IIS of the computer used to work with GeneXus, and
  • Is connected to the target (e.g., production) database.

2. Select Build All.

3. Go to the Build menu and select the Application Deployment tool option.

4. In the Deployment screen:

1. Select the Main objects to be included in the deployment.

2. In Target, select the option "Docker Image".

3. Set the following properties as indicated below (All fields have default values):

1. Docker base image property: Image that is used as a base to create the new one

2. Maintainer name property: Name of the Author of the image; it's set as part of the metadata of the image

3. Docker Environment variables property: All the environment variables you wish the image to have already instanced

4. Image WebApp location property: Path inside the docker image where the application runs

5. Docker image name property: Name of the generated docker image

5. Click on the Deploy button to create the Docker Image. The Output sends feedback about the process and the location of the generated files.

Now run the following command, in the Windows command prompt, to list the Docker images, including the one you created in the previous steps.

docker images

Steps to run the Docker Image

Java

Java environments generate images based on Linux. To run a container based on the previously created image, from the directory where the Dockerfile is located, execute the following command. See (run command).

docker run --rm -p 9999:8080 <Docker image name>

Where:

--rm
      Indicates that the container is deleted once it is shut down

-p 9999:8080
      Indicates that the port 8080 (Tomcat default) of the container is exposed as 9999 on the host

<Docker image name>
      Is the one created in the previous step

After successfully running this command, you can access the application's main object at http://localhost:9999/servlet/<Java package name>.<qualified object's name>.

.NET Framework (C#)

.NET Framework (C#) environments generate images based on Windows. To run a container based on the previously created image, execute the following command from the directory where the Dockerfile is located.

docker run --rm -p 9999:80 <Docker image name>

Where:

--rm
      Indicates that the container is deleted once it is shut down

-p 9999:80
      Indicates that the port 80 (IIS default) of the container is exposed as 9999 on the host

<Docker image name>
      Is the one created in the previous step

Note: After a while, an error will be shown in the output but you can ignore it (.ref https://github.com/Microsoft/aspnet-docker/issues/69).
ERROR ( message:Cannot find requested collection element. )
Applied configuration changes to section "system.applicationHost/applicationPools" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"

After successfully running this command, you can access the application's main object at http://localhost:9999/<qualified object's name>.aspx.

.NET

.NET environments generate images based on Linux. To run a container based on the previously created image, execute the following command.

docker run --rm -p 9999:80 -e ASPNETCORE_URLS="http://*:80" <Docker image name>

Where:

--rm
      Indicates that the container is deleted once it is shut down

-p 9999:80 
      Indicates that the port 80 (web default) is exposed as 9999 on the host

-e ASPNETCORE_URLS

     The parameter -e ASPNETCORE_URLS is an optional environmet variable for .NET, but it is required for .NET 8 as it specfies the port for ASP.NET Core. The default port can be changed to another value, for example:

docker run --rm -p 9999:5000 -e ASPNETCORE_URLS="http://*:5000" <Docker image name>

 

<Docker image name>
      Is the one created in the previous step

To access a remote database server using a non-fully-qualified hostname from the container, you may need to specify a DNS search prefix. For example, if the DataStore server name is 'SqlServerSrv,' and the fully qualified name is 'mycompany.local.SqlServerSrv,' you can specify the prefix as follows:

docker run --rm -p 9999:5000 -e ASPNETCORE_URLS="http://*:5000" --dns-search mycompany.local <Docker image name>

After successfully running this command, you can access the application's main object at http://localhost:9999/<qualified object's name>.aspx.

Restrictions

  • Using default Docker base images
    • In the .NET Framework and .NET generators, it is essential to ensure that you have an SSL certificate. If such a certificate is not available, it is advisable to avoid setting the Protocol specification property to HTTPS to prevent the generation of timeout messages.
    • Sites are accessed via HTTP

See Also

Troubleshooting deployment to Docker Containers
Application Deployment MSBuild tasks

FAQ

1) I already have my own images where I want my apps to run. Can I deploy my app to those?

Yes, you can. You can change the default base image to be used by GeneXus in the Docker base image property. There you can set your own image and the Docker client will try to pull it from a registry if it's not available on your computer. Keep in mind that the image WebApp location property might also need to be changed.

You can generate the Dockerfile even without the 'Docker for Windows' requirement. For that purpose, use this feature and select the option to deploy to Docker as usual. 
A warning will appear, 'warning: Dockerfile successfully created, but no docker image was generated because Docker client was not found.' in that case.

If you want to just create the package, use the "Only Package option" in GeneXus (or the Deploy to Docker MSBuild task). If you try to build the image and don't have the Docker engine up and running, you will get an error.

 

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant