Deploying using Docker
This section describes the steps to deploy sample ZIETrans application in Docker using either docker run or docker-compose.
Note : This example is only for the demonstration purpose.
Deploying using Docker run
Follow these steps to deploy the ZIETrans application using docker run command:
-
Create a ZIETrans project and export it as an ear.
-
Create a Dockerfile (or refer it from here using below code which deploys a simple ZIETrans application in a Liberty server.
# Use the official Liberty image as the base image FROM open-liberty:21.0.0.9-full-java8-openj9 # Copy ZIETrans application ear file to the Liberty dropins directory COPY ZIETrans.ear /config/dropins/ -
Navigate to the docker file location, add the ZIETrans ear file to this location, open the terminal and build the docker file using below command, which creates an image called ZIETrans.
docker build -t ZIETrans . -
Once the image is built successfully, deploy the ZIETrans application using below command.
Syntax:
docker run --name <container_name> -p <local-machine-port>:<container-port> -d <image-name>:<image_tag>Example:
docker run --name zietranscontainer -d -p 82:9080 ZIETrans -
After the successful deployment, access the ZIETrans application using below URL in the browser.
http://localhost:82/<ZIETransProjName> -
User can modify the Dockerfile to customize the base Liberty image or adjust any other build parameters based on your requirements.
Adding environmental variables
Environment variables can be either set during image creation through Docker File or while running the container through docker run command "-e" option.
To set the enviroment variables while building the image, user can use below code in DockerFile:
ENV ENV_Var_Name= ENV_Var_Value
Example:
ENV ZIETRANS_RUNTIME_CFG_ENV=/home/runtime
To set the enviroment variables while starting the container, user can use below command:
docker run --name <container_name> -p <local-machine-port>:<container-port> -e "<env-variable-name1>=<env-variable-value2>" -d <image-name>:<image-tag>
Example:
docker run -p 82:9080 -e ZIETRANS_RUNTIME_CFG_ENV:/home/runtime -d zietransimage:latest
For more information on ZIETrans specific environmental variables, refer to Application ENV variables
Adding volume mounts
To access the runtime logs and other information, user can add the volume mounts and save the required log files in the preffered location. Use below command to mount the local directory with the container.
docker run --name <container_name> -p <local-machine-port>:<container-port> -v <your-local-repo-path>:<container-folder-to-be-mounted> -d <image-name>:<image_tag>
Example:
docker run -p 82:9080 -v C:/zietrans/logs:/home/logs -d zietransimage:latest
Deploying Application using Docker Compose
-
Open a terminal window and change to the root directory where the docker-compose.yml is located in the downloaded docker compose configuration folder.
-
Make sure the docker-compose folder has read/write permission for volume requirements.
-
If needed user can edit the directories mapped in the docker compose file to their preferred location which is valid and has appropriate permissions.
-
Run the below command to start the container images
docker-compose up –d -
You can optionally check the container logs using the following command:
docker-compose logs -f <container_name> -
To stop all the containers run:
docker-compose down -
Once the command has been launched, be sure that the containers are started using the following command
docker ps -
After the successful deployment, access the ZIETrans application using below URL in the browser.
http://localhost:<mapped-port>/<zietransappname>