Docker在GitHub操作中构建错误标准_init_linux.go:228:Exec用户流程造成的:exec格式错误
使用Docker构建和部署我们的应用程序到AWS ECS群集。
Docker图像是在GitHub动作中构建的,并将其推向AWS ECR。
但是,当将图像部署到ECS群集中时,它会出现错误
standard_init_linux.go:228: exec user process caused: exec format error
dockerfile
FROM python:3.9.11-slim
ENV PYTHONUNBUFFERED=1
ARG APP_USER=app
RUN groupadd -r ${APP_USER} && useradd --no-log-init -r -m -g ${APP_USER} ${APP_USER}
RUN set -ex \
&& RUN_DEPS=" \
libpcre3 \
mime-support \
libmagic1 \
default-libmysqlclient-dev \
inkscape \
libcurl4-nss-dev libssl-dev \
" \
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
&& python -m pip install --upgrade pip \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /home/${APP_USER}/.config/inkscape \
&& chown -R ${APP_USER} /home/${APP_USER}/.config/inkscape \
# Create directories
&& mkdir /app/ \
&& mkdir /config/ \
&& mkdir /scripts/ \
&& mkdir -p /static_cdn/static_root/ \
&& chown -R ${APP_USER} /static_cdn/
COPY ./requirements/requirements.txt /
RUN set -ex \
&& BUILD_DEPS=" \
build-essential \
libpcre3-dev \
libpq-dev \
" \
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
&& pip install -r requirements.txt \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
&& rm -rf /var/lib/apt/lists/*
COPY ./src /app/
COPY pytest.ini /
COPY ./scripts/ /scripts/
COPY ./configs/ /configs/
COPY library_data /library_data
WORKDIR /app/
EXPOSE 8000
ENV UWSGI_WSGI_FILE=app/wsgi.py
ENV UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_HTTP_AUTO_CHUNKED=1 UWSGI_HTTP_KEEPALIVE=1 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy
ENV UWSGI_WORKERS=2 UWSGI_THREADS=4
ENV UWSGI_STATIC_MAP="/static/=/static_cdn/static_root/" UWSGI_STATIC_EXPIRES_URI="/static/.*\.[a-f0-9]{12,}\.(css|js|png|jpg|jpeg|gif|ico|woff|ttf|otf|svg|scss|map|txt) 315360000"
# Change to a non-root user
USER ${APP_USER}:${APP_USER}
ENTRYPOINT ["/scripts/docker/entrypoint.sh"]
和entrypoint.sh
#!/bin/sh
#set -e
safeRunCommand() {
cmnd="$*"
echo cmnd="$cmnd"
eval "$cmnd"
ret_code=$?
if [ $ret_code != 0 ]; then
printf "Error : [code: %d] when executing command: '$cmnd'\n" $ret_code
exit $ret_code
else
echo "Command run successfully: $cmnd"
fi
}
runDjangoCollectStatic() {
echo "Collecting static files"
cmnd="python manage.py collectstatic --noinput"
safeRunCommand "$cmnd"
echo "Done: Collecting static files"
}
runDjangoMigrate() {
echo "Migrating database"
safeRunCommand "python manage.py migrate --noinput"
echo "Done: Migrating database"
}
runDjangoCheckDeploy() {
echo "Checking Django deployment"
safeRunCommand "python manage.py check --deploy"
echo "Done: Checking Django deployment"
}
if [ "x$DEPLOYMENT_MODE" = 'xproduction' ]; then
echo "Running in production mode..."
runDjangoCheckDeploy
runDjangoCollectStatic
runDjangoMigrate
fi
if [ "x$DJANGO_MANAGE_COLLECTSTATIC" = 'xon' ] && [ ! "x$DEPLOYMENT_MODE" = 'xproduction' ]; then
runDjangoCollectStatic
fi
if [ "x$DJANGO_MANAGE_MIGRATE" = 'xon' ] && [ ! "x$DEPLOYMENT_MODE" = 'xproduction' ]; then
runDjangoMigrate
fi
# Accept other commands
exec "$@"
当相同图像时是在本地构建并将其推向ECR的,然后在没有任何修改的情况下工作正常。
通过从ECR中拉出图像并在本地运行,发出以下警告,但图像在本地运行良好的
docker pull ecr/image
docker run -it ecr/image bash
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
app@fc0e09fc9094:/app$
EC2机器类型为AMD(Graviton处理器)(M6G类)(M6G类)
编辑2
在服务器容器上运行UNAME -M
命令正在提供,
aarch64
而GitHub Action内置的图像正在提供
x86_64
Using Docker to build and deploy our application to the AWS ECS cluster.
The docker image is built in the Github actions and pushed to the AWS ECR.
But when the images are deployed to the ECS cluster, it gives the error
standard_init_linux.go:228: exec user process caused: exec format error
The content of the Dockerfile
FROM python:3.9.11-slim
ENV PYTHONUNBUFFERED=1
ARG APP_USER=app
RUN groupadd -r ${APP_USER} && useradd --no-log-init -r -m -g ${APP_USER} ${APP_USER}
RUN set -ex \
&& RUN_DEPS=" \
libpcre3 \
mime-support \
libmagic1 \
default-libmysqlclient-dev \
inkscape \
libcurl4-nss-dev libssl-dev \
" \
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
&& python -m pip install --upgrade pip \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /home/${APP_USER}/.config/inkscape \
&& chown -R ${APP_USER} /home/${APP_USER}/.config/inkscape \
# Create directories
&& mkdir /app/ \
&& mkdir /config/ \
&& mkdir /scripts/ \
&& mkdir -p /static_cdn/static_root/ \
&& chown -R ${APP_USER} /static_cdn/
COPY ./requirements/requirements.txt /
RUN set -ex \
&& BUILD_DEPS=" \
build-essential \
libpcre3-dev \
libpq-dev \
" \
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
&& pip install -r requirements.txt \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
&& rm -rf /var/lib/apt/lists/*
COPY ./src /app/
COPY pytest.ini /
COPY ./scripts/ /scripts/
COPY ./configs/ /configs/
COPY library_data /library_data
WORKDIR /app/
EXPOSE 8000
ENV UWSGI_WSGI_FILE=app/wsgi.py
ENV UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_HTTP_AUTO_CHUNKED=1 UWSGI_HTTP_KEEPALIVE=1 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy
ENV UWSGI_WORKERS=2 UWSGI_THREADS=4
ENV UWSGI_STATIC_MAP="/static/=/static_cdn/static_root/" UWSGI_STATIC_EXPIRES_URI="/static/.*\.[a-f0-9]{12,}\.(css|js|png|jpg|jpeg|gif|ico|woff|ttf|otf|svg|scss|map|txt) 315360000"
# Change to a non-root user
USER ${APP_USER}:${APP_USER}
ENTRYPOINT ["/scripts/docker/entrypoint.sh"]
and entrypoint.sh
#!/bin/sh
#set -e
safeRunCommand() {
cmnd="$*"
echo cmnd="$cmnd"
eval "$cmnd"
ret_code=$?
if [ $ret_code != 0 ]; then
printf "Error : [code: %d] when executing command: '$cmnd'\n" $ret_code
exit $ret_code
else
echo "Command run successfully: $cmnd"
fi
}
runDjangoCollectStatic() {
echo "Collecting static files"
cmnd="python manage.py collectstatic --noinput"
safeRunCommand "$cmnd"
echo "Done: Collecting static files"
}
runDjangoMigrate() {
echo "Migrating database"
safeRunCommand "python manage.py migrate --noinput"
echo "Done: Migrating database"
}
runDjangoCheckDeploy() {
echo "Checking Django deployment"
safeRunCommand "python manage.py check --deploy"
echo "Done: Checking Django deployment"
}
if [ "x$DEPLOYMENT_MODE" = 'xproduction' ]; then
echo "Running in production mode..."
runDjangoCheckDeploy
runDjangoCollectStatic
runDjangoMigrate
fi
if [ "x$DJANGO_MANAGE_COLLECTSTATIC" = 'xon' ] && [ ! "x$DEPLOYMENT_MODE" = 'xproduction' ]; then
runDjangoCollectStatic
fi
if [ "x$DJANGO_MANAGE_MIGRATE" = 'xon' ] && [ ! "x$DEPLOYMENT_MODE" = 'xproduction' ]; then
runDjangoMigrate
fi
# Accept other commands
exec "$@"
When the same image is built locally and pushed to ECR, then it works fine without any modification.
By pulling the image from ECR and running locally gives the following warning but the image is running fine locally
docker pull ecr/image
docker run -it ecr/image bash
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
app@fc0e09fc9094:/app$
EC2 machine type is AMD (Graviton Processor) (m6g class)
Edit 2
Running the uname -m
command on server containers is giving
aarch64
while the image built in GitHub action is giving
x86_64
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论