1. Preface
In the first ten chapters, we introduced the basic functions and use of Kong and the deployment based on docker. However, the deployment of Docker provided by the official website is based on the release of yum installation in the form of rpm, which is troublesome.
In this chapter, we introduce a source-based approach to building docker images.
2. Review of the official Docker mirror
The Kong image used here can be found in DockerHub, which is provided by the official docker, not uploaded by third-party users. The corresponding Docker file, such as kong: 1.0.3-centos docker file, is given on the page.
FROM centos:7 LABEL maintainer="Kong Core Team <team-core@konghq.com>" ENV KONG_VERSION 1.0.3 ARG SU_EXEC_VERSION=0.2 ARG SU_EXEC_URL="https://github.com/ncopa/su-exec/archive/v${SU_EXEC_VERSION}.tar.gz" RUN yum install -y -q gcc make unzip \ && curl -sL "${SU_EXEC_URL}" | tar -C /tmp -zxf - \ && make -C "/tmp/su-exec-${SU_EXEC_VERSION}" \ && cp "/tmp/su-exec-${SU_EXEC_VERSION}/su-exec" /usr/bin \ && rm -fr "/tmp/su-exec-${SU_EXEC_VERSION}" \ && yum autoremove -y -q gcc make \ && yum clean all -q \ && rm -fr /var/cache/yum/* /tmp/yum_save*.yumtx /root/.pki RUN useradd --uid 1337 kong \ && yum install -y https://bintray.com/kong/kong-community-edition-rpm/download_file?file_path=centos/7/kong-community-edition-$KONG_VERSION.el7.noarch.rpm \ && yum clean all COPY docker-entrypoint.sh /docker-entrypoint.sh ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 8000 8443 8001 8444 STOPSIGNAL SIGTERM CMD ["kong", "docker-start"]
From this you can see that kong in CentOS is published in the form of rpm and installed in yum:
yum install -y https://bintray.com/kong/kong-community-edition-rpm/download_file?file_path=centos/7/kong-community-edition-$KONG_VERSION.el7.noarch.rpm
This is a bit cumbersome, because if you modify kong, you need to type it into rpm file before you can re-create the image. You need a Docker file that generates the image directly using Kong source code.
Let's get down to business.
3. Use source code to generate mirror Docker file
Make the Base image first to reduce the production time of the subsequent image. Use the following Docker file:
FROM centos:7 LABEL maintainer="https://github.com/yuelicn/containers" RUN yum install -y yum-utils epel-release \ && yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo \ && yum install -y openresty-1.13.6.2 openresty-resty-1.13.6.2 luarocks make git gcc lua-devel openssl-devel m4 \ && yum install -y libyaml \ && yum install -y libyaml-devel \ && yum clean all
Generate mirror yueli/openresty:centos:
docker build -f ./Dockerfile.base -t yueli/openresty:centos .
Make a kong Image Based on the Base image, copy the kong source code into the image, and install it. Dockerfile is as follows
FROM yueli/openresty:centos LABEL maintainer="https://github.com/yuelicn/containers" ENV KONG_VERSION 1.2.1 COPY ./kong /kong COPY ./kong.sh /kong.sh COPY ./kong.conf /kong.conf COPY ./docker-entrypoint.sh /docker-entrypoint.sh RUN useradd --uid 1337 kong && pushd /kong && make install && popd && chmod +x /kong.sh && ln -s /kong.sh /usr/bin/kong ENTRYPOINT ["/docker-entrypoint.sh"] EXPOSE 8000 8443 8001 8444 STOPSIGNAL SIGTERM CMD ["kong", "docker-start"]
All relevant documents are located in https://github.com/yuelicn/do... perhaps https://github.com/yuelicn/co... The following operations can be used directly:
git clone https://github.com/yuelicn/containers.git cd docker-kong make base make prod
perhaps
git clone https://github.com/yuelicn/docker-kong docker build -f ./Dockerfile-dev -t yueli/kong:1.2.1 .
Either way.
Note: In the https://github.com/yuelicn/do... In the project docker-entrypoint.sh, I added kong initialization execution. If you want to perform initialization manually, you can remove it.
So we can happily use the source code to build the mirror.
For more information about Kong Gateway, please move Enterprise API Gateway Kong