
This assumes you have installed Docker on Linux and Docker is running.
A Docker image contains the code used to create a Docker container, such as creating a Nginx web server, or a mySQL server, or a home grown app, and the list goes on. In this way, an image is like a template used to create a container. An image is kind of like a virtual machine, but much more light weight, using significantly less storage a memory (containers are usually megabytes in size).
The docker pull command can be used to pull down the Kong and Postgres database images.
docker pull kong/kong-gateway
docker pull library/postgres
Or you could create Dockerfile so that the Dockerfile contains something like this.
FROM kong/kong-gateway
Then use the docker build command to create the image, running this command in the same directory as the Dockerfile.
docker build . --tag kong:latest
The docker images command can then be used to confirm the Kong and Postgres images were pulled down.
~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kong/kong-gateway latest 105b54dc64f1 32 hours ago 310 MB
postgres latest 29dd0a82ea20 2 weeks ago 315 MB
The docker network create command can be used to create a dedicated bridge network for Kong.
docker network create kong-network
The docker network ls command can be used to confirm the dedicated Kong bridge network was created.
~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
7e6e54bde697 kong-network bridge local
The docker run command can be used to create and start a PostgresSQL database container.
- The --name option is used to name the container kong-postgres
- The --network option is used to use the kong-network
- The --publish option is used to configure the Docker server and Postgres container to listen on port 5432
- The --env option is used to define variables
- The --restart unless-stopped option is used so that the container is started if the Docker server is restarted
- The postgres:latest image is used
docker run
--detach
--name kong-postgres-database
--network kong-network
--publish 5432:5432
--env POSTGRES_DB=kong
--env POSTGRES_USER=kong
--env POSTGRES_PASSWORD=itsasecret
--restart unless-stopped
postgres:latest
The docker container ls command can be used to confirm the Postgres container is up and running.
~]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8ad22fabc22 postgres "docker-entrypoint.s…" 6 minutes ago Up About a minute 0.0.0.0:5432->5432/tcp kong-postgres
The docker exec command can be used to confirm that you are able to interact with the Postgres database in the container using the Postgres psql command.
~]# docker exec kong-postgres-database psql --version
psql (PostgresSQL) 13.4 (Debian 13.4-1.pgdg100+1)
Prepare the Postgres database.
docker run
--rm
--network kong-network
--env KONG_DATABASE=postgres
--env KONG_PG_HOST=kong-postgres-database
--env KONG_PG_PASSWORD=itsasecret
--env KONG_PASSWORD=itsasecret
kong/kong-gateway:latest
kong migrations bootstrap
Create the start the Kong gateway container.
docker run
--detach
--name kong
--network kong-network
--env KONG_DATABASE=postgres
--env KONG_PG_HOST=kong-postgres-database
--env KONG_PG_PASSWORD=itsasecret
--env KONG_ADMIN_ACCESS_LOG=/dev/stdout
--env KONG_ADMIN_ERROR_LOG=/dev/stderr
--env KONG_ADMIN_LISTEN=0.0.0.0:8001
--env KONG_ADMIN_GUI_URL=http://<hostname or ip address Docker server>:8002
--env KONG_PASSWORD=itsasecret
--env KONG_PROXY_ACCESS_LOG=/dev/stdout
--env KONG_PROXY_ERROR_LOG=/dev/stderr
--publish 8000:8000
--publish 8001:8001
--publish 8002:8002
--publish 8003:8003
--publish 8004:8004
--publish 8443:8443
--publish 8444:8444
--publish 8445:8445
--restart unless-stopped
kong/kong-gateway:latest
The docker container ls command can be used to confirm the Postgres and Kong containers are up and running.
~]$ sudo docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
593607ba5a19 kong/kong-gateway:latest "/docker-entrypoint.…" 14 seconds ago Up 13 seconds (healthy) 0.0.0.0:8000-8003->8000-8003/tcp, :::8000-8003->8000-8003/tcp, 8004/tcp, 0.0.0.0:8443-8445->8443-8445/tcp, :::8443-8445->8443-8445/tcp, 8446-8447/tcp kong
93c1a7f163a7 postgres "docker-entrypoint.s…" 16 minutes ago Up 16 minutes 0.0.0.0:5432->5432/tcp kong-postgres
You should now be able to access the Kong GUI at http://<hostname or ip address Docker server>:8002.
And the following command should return JSON containing the current status of Kong.
curl --request GET http://<hostname or ip address Docker server>:8001/status
Did you find this article helpful?
If so, consider buying me a coffee over at