Build and run API Portal using Dockerfile

This section describes how to build an API Portal Docker image using the Dockerfile in the sample package. It also describes how to download and run MySQL and Redis Docker containers, and how to run API Portal in Docker containers.

Note   MySQL and Redis Docker images are not included with the API Portal Docker sample package. You must download them separately from Docker Hub.

The process is as follows:

  1. Upload API Portal Docker package
  2. Download and run database container
  3. Build and run API Portal Docker container
  4. Download and run Redis container
  5. Encrypt the Public API user password (optional)

Prerequisites

The following components are required on your system before deploying API Portal in a Docker container:

The monitoring feature of API Portal, which enables your API consumers to monitor application and API usage, also requires the following software:

  • API Gateway Analytics 7.6.2 (and an appropriate metrics database)

The following are the recommended hardware disk space and memory requirements for the Docker host machine for a single node sample architecture:

  • 100 GB or more disk space
  • 8 GB or more RAM

Upload API Portal Docker package

Follow these steps to upload the Docker sample package to your Docker host machine:

  1. Download the API Portal Docker sample package from Axway Support at https://support.axway.com.
  2. Upload the package to your Docker host machine.
  3. Unzip the package.

The package includes:

  • readme.md – Details the contents of the package and provides brief instructions to build and run API Portal in Docker.
  • Dockerfile – Enables you to build an API Portal Docker image using the docker build command.
  • Various scripts and files that are used to build the API Portal Docker image. See the readme.md for full details of these files.
  • docker-compose.yml sample – Enables you to use Docker Compose to run your entire API Portal Docker deployment using a single docker-compose up command.

Download and run database container

To run a database Docker container, complete the following steps:

  1. Ensure that you are logged in to your Docker host machine as the root user.
  2. Download a Docker image for your chosen database from Docker Hub. For example, to download a MySQL image, enter the following command:
  3. $ docker pull mysql:5.7
  4. Note   The database must be supported by API Portal. For more information on supported databases, see Software requirements.
  5. Run the database container following the instructions on Docker Hub. For example, to run a MySQL Docker container:
  6. $ docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=XXXXX -p 3306:3306 mysql:5.7
  7. Verify that the database container is running:
  8. $ docker ps -a | grep <your database container name>
Note   When the database container is started it creates a volume to store the data from the database. This volume is created with a random name which you can identify using docker inspect.

Build and run API Portal Docker container

To build the Docker image and run the API Portal Docker container, follow these steps:

  1. Ensure that you are logged in to your Docker host machine as the root user.
  2. Change to the directory where you unzipped the Docker sample package.
  3. Build the API Portal image. For example, enter the following command to build the image and tag it as apiportal:7.6.2:
  4. $ docker build -t apiportal:7.6.2
  5. Check the IP address of the database container you started earlier:
  6. $ docker inspect <your database container name>
  7. Create data volumes for API Portal customized data, for example:
  8. $ docker volume create templates
    $ docker volume create images
  9. Tip   For more information about Docker volumes and a complete list of directories which you should preserve, see Create Docker data volumes for persistence.
  10. Run a container from the API Portal Docker image with the same data volumes. For example:
  11. $ docker run -it --name apiportal -e MYSQL_HOST=172.19.0.2 -e MYSQL_PORT=3306 
    -e MYSQL_ROOT_PASSWORD=XXXXX -e MYSQL_USERNAME=joomla -e MYSQL_PASSWORD=XXXXX
    -e MYSQL_DBNAME=joomla -e APIMANAGER_HOST=XXXXX -e APIMANAGER_PORT=XXXXX -p 443:443
    -v templates:/opt/axway/apiportal/htdoc/templates
    -v images:/opt/axway/apiportal/htdoc/images apiportal:7.6.2

This example performs the following:

  • Runs an API Portal Docker container from an image named apiportal:7.6.2
  • Sets environment variables for connecting to the MySQL container.
  • Sets environment variables for connecting to API Manager.
  • Binds port 443 of the container to port 443 on the host machine.
  • Mounts volumes for customized data.
Note   You can safely ignore the following messages, which might be displayed when running this command:
"ERROR 1060 (42S21) at line 1: Duplicate column name 'termsAndCond'"
"AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using <IP address>. 
Set the 'ServerName' directive globally to suppress this message"

API Portal is now running in a Docker container.

Before you can use API Portal, you must link it to your API Manager. For more details, see Connect API Portal to API Manager.

Download and run Redis container

For better performance and scalability, you can configure API Portal to cache APIs in a Redis cache. Using a Redis cache is recommended if you plan to expose hundreds of APIs, or you plan to connect API Portal to more than one API Manager.

To download and run a Redis Docker container, complete the following steps:

  1. Download the Redis Docker image from Redis on Docker Hub. For example, enter the following command:
  2. $ docker pull redis:latest
  3. Run the Redis Docker container, for example:
  4. $ docker run -d --name redis redis:latest

Redis is now running in a Docker container. To configure API Portal to use the Redis cache, follow these steps:

  1. Check the IP address of the Redis container:
  2. $ docker inspect <your Redis container name>
  3. Enter the following command to connect to the API Portal container:
  4. $ docker exec -it <your API Portal container name> /bin/bash
  5. Open the following configuration file for editing:
  6. /opt/axway/apiportal/htdoc/configuration.php
  7. Locate the following line:
  8. redis_server_host = 'localhost';
  9. Change localhost to the IP address of the Redis container and save the file.

Encrypt the Public API user password (optional)

To use the Public API mode in API Portal you must first run a script to encrypt the Public API user password and specify a directory to store the encryption key.

Perform the following steps after the API Portal Docker container is started:

  1. Access the API Portal Docker container using the following command:
  2. docker exec -it <your API Portal container name> bash
  3. Change to the directory where the apiportal_encryption.sh script is located and execute the script. For example:
  4. cd /
    ./apiportal_encryption.sh
  5. Enter the full path to the file in which to store the encryption key.

The directory is created along with a file. The last segment of the directory is the file name, for example: /sample/directory/for/encryption/key creates an empty file named "key" in the desired directory.

After the script is finished, re-enter the password for the Public API user in JAI to encrypt and store it correctly. For more details see Configure Public API in the API Portal Administrator Guide.

Note   You do not need to rerun the encryption script every time you start and stop the API Portal Docker container, but if you remove the container and create a new one using the same database (for example, when upgrading or setting up HA), you must rerun the encryption script and re-enter the password for the Public API user in JAI.

Related Links