1、使用最新版Mendix Docker Buildpack
https://github.com/mendix/docker-mendix-buildpack/tree/latest
2、克隆最新版Buildpack,修改<TAG>
这里会产生一个docker-mendix-buildpack文件夹,以后所有的工作都在这个文件夹下进行
git clone --branch <TAG> --config core.autocrlf=false https://github.com/mendix/docker-mendix-buildpack
3、安装Docker
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum install -y docker-ce service docker start systemctl enable docker.service
4、创建基础镜像
docker build -t mendix-rootfs:app -f rootfs-app.dockerfile .
docker build -t mendix-rootfs:builder -f rootfs-builder.dockerfile .
4.1、rootfs-builder.dockerfile这个基础镜像需要特殊处理,在安装mono依赖的时候经常超时,所以需要下载依赖,手动安装
4.2、安装一个registry.access.redhat.com/ubi8/ubi-minimal:latest镜像,运行容器后,在容器里运行下面命令,下载所有依赖
最容易在这里失败,Mono这个站点下载依赖巨慢,导致超时,或者安装不完全导致错误。https://download.mono-project.com/repo/centos8-stable/。找一个网络环境好的机器把依赖下载下来。
yum install mono-core-5.20.1.34 --downloadonly --downloaddir=/opt/mendix/mono/
4.3、在docker-mendix-buildpack下创建一个depen,把下载好的依赖放到depen中
4.4、修改rootfs-builder.dockerfile为下面
# Dockerfile to create a Mendix Docker image based on either the source code or # Mendix Deployment Archive (aka mda file) FROM --platform=linux/amd64 registry.access.redhat.com/ubi8/ubi-minimal:latest #This version does a full build originating from the Ubuntu Docker images LABEL Author="Mendix Digital Ecosystems" LABEL maintainer="[email protected]" # Set the locale ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 # CF buildpack version ARG CF_BUILDPACK=v5.0.16 # CF buildpack download URL ARG CF_BUILDPACK_URL=https://kkgithub.com/mendix/cf-mendix-buildpack/releases/download/${CF_BUILDPACK}/cf-mendix-buildpack.zip # Set the user ID ARG USER_UID=1001 ENV USER_UID=${USER_UID} # Allow specification of debugging options ARG BUILDPACK_XTRACE # Add mono repo COPY --chown=0:0 scripts/mono/xamarin.gpg /etc/pki/rpm-gpg/RPM-GPG-KEY-mono-centos8-stable COPY --chown=0:0 scripts/mono/mono-centos8-stable.repo /etc/yum.repos.d/mono-centos8-stable.repo #修改的地方1: Copy denpendencies COPY --chown=0:0 /depen /opt/depen/ # install dependencies & remove package lists RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm && \ sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel* && \ sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel* && \ microdnf update -y && \ microdnf module enable nginx:1.20 -y && \ microdnf install -y wget curl glibc-langpack-en python311 openssl tar gzip unzip libpq nginx nginx-mod-stream binutils fontconfig findutils binutils && \ microdnf clean all && rm -rf /var/cache/yum #修改的地方2: install dependencies RUN rpm -ivh --nodeps --force /opt/depen/* #修改的地方3:去掉mono-core-5.20.1.34 libgdiplus0两个依赖,上面手动安装了 RUN microdnf install -y java-11-openjdk-headless java-11-openjdk-devel tzdata-java libicu && \ microdnf clean all && rm -rf /var/cache/yum # Set nginx permissions RUN touch /run/nginx.pid && \ chown -R 1001:0 /var/log/nginx /var/lib/nginx /run/nginx.pid &&\ chmod -R g=u /var/log/nginx /var/lib/nginx /run/nginx.pid # Pretend to be Ubuntu to bypass CF Buildpack's check RUN rm /etc/*-release && printf 'NAME="Ubuntu"\nID=ubuntu\nVersion="22.04 LTS (Jammy Jellyfish)"\nVERSION_CODENAME=jammy\n' > /etc/os-release # Set python alias to python3 (required for Datadog) RUN alternatives --set python /usr/bin/python3 # Download and prepare CF Buildpack # Switch CF Buildpack to use Python 3.10+ compatibility ENV CF_STACK cflinuxfs4 # Each comment corresponds to the script line: # 1. Create all directories needed by scripts # 2. Download CF buildpack # 3. Extract CF buildpack # 4. Delete CF buildpack zip archive # 5. Update ownership of /opt/mendix so that the app can run as a non-root user # 6. Update permissions of /opt/mendix so that the app can run as a non-root user RUN mkdir -p /opt/mendix/buildpack /opt/mendix/build &&\ ln -s /root /home/vcap &&\ echo "Downloading CF Buildpack from ${CF_BUILDPACK_URL}" &&\ curl -fsSL ${CF_BUILDPACK_URL} -o /tmp/cf-mendix-buildpack.zip && \ python3 -m zipfile -e /tmp/cf-mendix-buildpack.zip /opt/mendix/buildpack/ &&\ rm /tmp/cf-mendix-buildpack.zip &&\ chown -R ${USER_UID}:0 /opt/mendix &&\ chmod -R g=u /opt/mendix # Copy python scripts which execute the buildpack (exporting the VCAP variables) COPY scripts/compilation.py scripts/git scripts/mono-adapter /opt/mendix/buildpack/ # Install the buildpack Python dependencies RUN PYTHON_BUILD_RPMS="python3.11-pip python3.11-devel libffi-devel gcc" && \ microdnf install -y $PYTHON_BUILD_RPMS && \ rm /opt/mendix/buildpack/vendor/wheels/* && \ chmod +rx /opt/mendix/buildpack/bin/bootstrap-python && /opt/mendix/buildpack/bin/bootstrap-python /opt/mendix/buildpack /tmp/buildcache && \ microdnf remove -y $PYTHON_BUILD_RPMS && microdnf clean all && rm -rf /var/cache/yum # Add the buildpack modules ENV PYTHONPATH "$PYTHONPATH:/opt/mendix/buildpack/lib/:/opt/mendix/buildpack/:/opt/mendix/buildpack/lib/python3.11/site-packages/"
5、在docker-mendix-buildpack下创建project文件夹,把Mendix应用目录下文件拷贝到这个文件夹下
6、运行docker命令创建Mendix应用镜像
docker build --tag mendix/mendix-buildpack:v1.2 .
7、创建一个postgres数据库镜像
docker run -id --name=postgresql -p 5432:5432 -e POSTGRES_PASSWORD=123456 -e LANG=C.UTF-8 postgres
8、运行mendix应用镜像,注意ADMIN_PASSWORD参数,必须符合密码策略
docker run -it --link=postgresql -e ADMIN_PASSWORD=Pass123@word -e DATABASE_ENDPOINT=postgres://postgres:123456@postgresql:5432/mendix mendix/mendix-buildpack:v1.2
到这里基本Mendix应用就可以运行了。
标签:opt,buildpack,--,mendix,&&,Mendix,镜像,Docker,docker From: https://www.cnblogs.com/qiumc/p/18096633