Skip to content

Run Container

Containers are a best practice for deployment, and offer several advantages for development. This outlines a typical scenario for running and testing API Logic Server projects prior to deployment.

Container Overview

Running Containers

You can run your container locally, or from DockerHub. Running locally is clearly a good choice for development.

 

Local Testing

You will typically want to test your image before pushing it to DockerHub. Use the run-image, as shown below1.

For example, to run your project container directly, you can

sh devops/docker-image/run_image.sh run_image.sh

 

environment variables

Note you can use env variables to configure your servers and ports. For more information, click here.

 

Arm machines

The procedures described here presume a team that uses amd (Intel) machines. Docker has different procedures to deal with arm-based Macs (M1, M2...).

If you use the procedures above, Docker will create images for amd. Such images will run slowly on arm, but in most cases that's fine for dev testing.

 

Multi-architecture images

You can build images that operate under either environment.

However, this is not done using the docker build command shown here. Instead, you use docker buildx, which must be performed in the context of a build environment. For an excellent article showing how to do this, click here.

 

Team Testing

Once you have pushed images to DockerHub, your fellow developers can run them in their local environments.

 

Cloud Testing

Cloud container testing is significantly more challenging that in an IDE. There are some steps we recommend that can make it easier1:

  1. Test with env variables - cloud containers pass parameters using env variables, typically not with command line arguments. These typically identify your database locations etc.

    • A VSCode Run configuration ApiLogicServer ENV is provided for this, so you can begin testing in your IDE.
  2. Use the VERBOSE env variable to activate logging

  3. Then test by running your container locally, setting env variables per your OS. See the CLI examples shown above.

ApiLogicServer Container upgrades

You can update your image to a new version:

docker pull apilogicserver/api_logic_server

If you update your ApiLogicServer container to a new version, your existing VSCode projects may appear to be damaged. You can fix them easily:

  1. Click the Dev Container button (in the lower left)
  2. Choose Rebuild Container

 

Start docker and load/run API Logic Project from GitHub

The api_logic_server image supports startup arguments so you can control the api_logic_server container, by running a startup script. You can run your own script, or use the pre-supplied script (/home/api_logic_server/bin/run-project.sh) to load/run a git project. For example:

docker run -it --name api_logic_server --rm --net dev-network -p 5656:5656 -p 5002:5002 -v ${PWD}:/localhost apilogicserver/api_logic_server sh /home/api_logic_server/bin/run-project.sh https://github.com/valhuber/Tutorial-ApiLogicProject.git /localhost/Project-Fixup.sh

will load the pre-built sample project from git, and run it. Prior to execution it runs /localhost/Project-Fixup.sh, which in this case resets ui/admin files, like this:

#!/bin/bash

echo " "
echo "Project-Fixup script running"
pwd; ls
echo " "

cp ui/admin/admin_custom_nw.yaml ui/admin/admin.yaml

Instead of using a startup script, you can also use environment variables to achieve the same effect:

docker run -it --name api_logic_server --rm --net dev-network -p 5656:5656 -p 5002:5002 -v ${PWD}:/localhost   -e APILOGICSERVER_GIT='https://github.com/valhuber/Tutorial-ApiLogicProject.git' -e APILOGICSERVER_FIXUP='/localhost/Project-Fixup.sh' apilogicserver/api_logic_server

  1. Several changes were made as of release 9.01.17. It is available as preview; click here