Build your own Docker images

Kong is distributed as prebuilt apk, deb, and rpm packages, in addition to official Docker images hosted on DockerHub

Kong builds and verifies Debian and RHEL images for use in production. Alpine images are provided for development purposes only as they contain development tooling such as git for plugin development purposes.

Our Debian and RHEL images are built with minimal dependencies (as of Kong Gateway 3.0) and run through automated security scanners before being published. Any vulnerabilities detected in supported images will be addressed in the next available patch release.

If you would like to build your own images to further customise the base image and any dependencies, follow the instructions below:

  1. Download docker-entrypoint.sh script from docker-kong and make it executable:

    1. chmod +x docker-entrypoint.sh
  2. Download the Kong Gateway package:

  3. Create a Dockerfile, ensuring you replace the filename by the first COPY with the name of the Kong Gateway file you downloaded in step 2:

    Debian

    Ubuntu

    RHEL

    Alpine

    1. FROM debian:bullseye-slim
    2. COPY kong.deb /tmp/kong.deb
    3. RUN set -ex; \
    4. apt-get update \
    5. && apt-get install --yes /tmp/kong.deb \
    6. && rm -rf /var/lib/apt/lists/* \
    7. && rm -rf /tmp/kong.deb \
    8. && chown kong:0 /usr/local/bin/kong \
    9. && chown -R kong:0 /usr/local/kong \
    10. && ln -s /usr/local/openresty/bin/resty /usr/local/bin/resty \
    11. && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit \
    12. && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/lua \
    13. && ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/bin/nginx \
    14. && kong version
    15. COPY docker-entrypoint.sh /docker-entrypoint.sh
    16. USER kong
    17. ENTRYPOINT ["/docker-entrypoint.sh"]
    18. EXPOSE 8000 8443 8001 8444 8002 8445 8003 8446 8004 8447
    19. STOPSIGNAL SIGQUIT
    20. HEALTHCHECK --interval=10s --timeout=10s --retries=10 CMD kong health
    21. CMD ["kong", "docker-start"]
    1. FROM ubuntu:20.04
    2. COPY kong.deb /tmp/kong.deb
    3. RUN set -ex; \
    4. apt-get update \
    5. && apt-get install --yes /tmp/kong.deb \
    6. && rm -rf /var/lib/apt/lists/* \
    7. && rm -rf /tmp/kong.deb \
    8. && chown kong:0 /usr/local/bin/kong \
    9. && chown -R kong:0 /usr/local/kong \
    10. && ln -s /usr/local/openresty/bin/resty /usr/local/bin/resty \
    11. && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit \
    12. && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/lua \
    13. && ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/bin/nginx \
    14. && kong version
    15. COPY docker-entrypoint.sh /docker-entrypoint.sh
    16. USER kong
    17. ENTRYPOINT ["/docker-entrypoint.sh"]
    18. EXPOSE 8000 8443 8001 8444 8002 8445 8003 8446 8004 8447
    19. STOPSIGNAL SIGQUIT
    20. HEALTHCHECK --interval=10s --timeout=10s --retries=10 CMD kong health
    21. CMD ["kong", "docker-start"]
    1. FROM registry.access.redhat.com/ubi8/ubi:8.1
    2. COPY kong.rpm /tmp/kong.rpm
    3. RUN set -ex; \
    4. yum install -y /tmp/kong.rpm \
    5. && rm /tmp/kong.rpm \
    6. && chown kong:0 /usr/local/bin/kong \
    7. && chown -R kong:0 /usr/local/kong \
    8. && ln -s /usr/local/openresty/bin/resty /usr/local/bin/resty \
    9. && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit \
    10. && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/lua \
    11. && ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/bin/nginx \
    12. && kong version
    13. COPY docker-entrypoint.sh /docker-entrypoint.sh
    14. USER kong
    15. ENTRYPOINT ["/docker-entrypoint.sh"]
    16. EXPOSE 8000 8443 8001 8444 8002 8445 8003 8446 8004 8447
    17. STOPSIGNAL SIGQUIT
    18. HEALTHCHECK --interval=10s --timeout=10s --retries=10 CMD kong health
    19. CMD ["kong", "docker-start"]
    1. FROM alpine:latest
    2. COPY kong.apk.tar.gz /tmp/kong.apk.tar.gz
    3. RUN set -ex; \
    4. apk add --no-cache --virtual .build-deps tar gzip \
    5. && tar -C / -xzf /tmp/kong.apk.tar.gz \
    6. && apk add --no-cache libstdc++ libgcc openssl pcre perl tzdata libcap zlib zlib-dev bash curl ca-certicates \
    7. && adduser -S kong \
    8. && addgroup -S kong \
    9. && mkdir -p "/usr/local/kong" \
    10. && chown -R kong:0 /usr/local/kong \
    11. && chown kong:0 /usr/local/bin/kong \
    12. && chmod -R g=u /usr/local/kong \
    13. && rm -rf /tmp/kong.tar.gz \
    14. && ln -s /usr/local/openresty/bin/resty /usr/local/bin/resty \
    15. && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit \
    16. && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/lua \
    17. && ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/bin/nginx \
    18. && apk del .build-deps \
    19. && kong version
    20. COPY docker-entrypoint.sh /docker-entrypoint.sh
    21. USER kong
    22. ENTRYPOINT ["/docker-entrypoint.sh"]
    23. EXPOSE 8000 8443 8001 8444 8002 8445 8003 8446 8004 8447
    24. STOPSIGNAL SIGQUIT
    25. HEALTHCHECK --interval=10s --timeout=10s --retries=10 CMD kong health
    26. CMD ["kong", "docker-start"]
  4. Build your image:

    1. docker build --no-cache -t kong-image .
  5. Test that the image built correctly:

    1. docker run -it --rm kong-image kong version
  6. To run Kong Gateway and process traffic, follow the Docker install instructions, replacing the image name with your custom name.