linux 删除Curl和libcurl或将其更新到Nginx基础镜像中Docker的最新版本(>=8.0)

fiei3ece  于 5个月前  发布在  Linux
关注(0)|答案(2)|浏览(66)

我有一个名为docker-base的基础镜像,它有一个Dockerfile,如下所示:

FROM nginx:latest

# Create app directory
WORKDIR /var/www/app

RUN rm /etc/nginx/conf.d/default.conf

# Install app dependencies
COPY app-nginx.conf /etc/nginx/conf.d

COPY motd /etc/motd

RUN chmod 0644 /etc/motd; echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/motd' >> /etc/bash.bashrc

COPY usersessiontimout.sh /etc/profile.d/usersessiontimout.sh

RUN chmod +x /etc/profile.d/usersessiontimout.sh

EXPOSE 8000

字符串
它使用最新的节点版本和图像是建立使用debainbookworm如下所示,当我从图像运行容器

root@e4f1d0771272:/var/www/app# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"


但它显示了curl和libcurl的版本,如下所示

docker exec e4f1d0771272 dpkg -l | grep curl
ii  curl                      7.88.1-10+deb12u4              arm64        command line tool for transferring data with URL syntax
ii  libcurl4:arm64            7.88.1-10+deb12u4              arm64        easy-to-use client-side URL transfer library (OpenSSL flavour)


我尝试将其更新到版本(>=8.0),但根据official document,nginx使用的debian软件包中的最新curl版本是7.88.1。
我尝试通过在上面的Dockerfile中添加以下内容来从基础映像中删除curl和libcurl。

RUN apt-get remove -y --auto-remove curl libcurl


但是当我使用base构建依赖镜像并运行容器时,它会不断重新启动。我的依赖镜像Dockerfile如下:

# Stage 1: Build stage
FROM node:12.3.1-alpine AS build

# Use different mirrors
RUN sed -i -e 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

# Install necessary packages using the 'apk' package manager
RUN apk update && \
    apk add --no-cache wget build-base openssl-dev

# Set the source folder
ARG SOURCE_FOLDER="./"
ARG BUILD_VERSION
ARG NPM_TOKEN

# Create app directory
WORKDIR /var/www/app

# Bundle app source
COPY ${SOURCE_FOLDER} .

RUN apk update && apk upgrade && \
    apk add --no-cache bash git openssh && \
    npm config set unsafe-perm true && \
    echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc && \
    npm i -g @myorg/lsc && \
    npm i --quiet --cache=./npm-cache

# Build the application
RUN NODE_OPTIONS=--max_old_space_size=4096 lsc build site --output-hashing all --buildVersion=$BUILD_VERSION && \
    rm -f .npmrc

# Stage 2: Final stage
FROM myorg/docker-base

# Copy only the necessary artifacts from the build stage
COPY --from=build /var/www/app/dist/ngx-rsc-app /var/www/app

# Install necessary packages using 'apt-get' package manager
RUN apt-get update 

# Switch back to app directory
WORKDIR /var/www/app


这是生成的依赖映像的容器日志中的错误

root@ip:~# docker logs -f 77666b51984a
exec /docker-entrypoint.sh: exec format error
exec /docker-entrypoint.sh: exec format error
exec /docker-entrypoint.sh: exec format error
exec /docker-entrypoint.sh: exec format error


有什么想法为什么它抛出这个错误和可能的解决方案?还有,有没有更好的方法来删除现有的curl和libcurl,同时保持容器健康?或者更新到版本>=8.0?

ccrfmcuu

ccrfmcuu1#

嗯. docker-entrypoint.sh
在任何情况下,exec()系统调用要能够执行shell脚本,它需要(a)设置x位,即chmod +x docker-entrypoint.sh。(b)它需要在开始时设置#!/bin/bash(或任何shell)。该错误将表明它可能没有。

kqqjbcuj

kqqjbcuj2#

有效的解决方案是使用基于alpine image的nginx,它没有安装curl和libcurl包。我保留了myorg/docker-base的nginx配置。下面是完整的解决方案:

我的docker-base镜像的Dockerfile

FROM nginx:latest

# Create app directory
WORKDIR /var/www/app

RUN rm /etc/nginx/conf.d/default.conf

# Install app dependencies
COPY app-nginx.conf /etc/nginx/conf.d

COPY motd /etc/motd

RUN chmod 0644 /etc/motd; echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/motd' >> /etc/bash.bashrc

COPY usersessiontimout.sh /etc/profile.d/usersessiontimout.sh

RUN chmod +x /etc/profile.d/usersessiontimout.sh

EXPOSE 8000

字符串

我的依赖镜像的Dockerfile

# Stage 1: Build stage
FROM node:12.3.1-alpine AS build

# Use different mirrors
RUN sed -i -e 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

# Install necessary packages using the 'apk' package manager
RUN apk update && \
    apk add --no-cache wget build-base openssl-dev

# Set the source folder
ARG SOURCE_FOLDER="./"
ARG BUILD_VERSION
ARG NPM_TOKEN

# Create app directory
WORKDIR /var/www/app

# Bundle app source
COPY ${SOURCE_FOLDER} .

RUN apk update && apk upgrade && \
    apk add --no-cache bash git openssh && \
    npm config set unsafe-perm true && \
    echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc && \
    npm i -g @myorg/lsc && \
    npm i --quiet --cache=./npm-cache

# Build the application
RUN NODE_OPTIONS=--max_old_space_size=4096 lsc build site --output-hashing all --buildVersion=$BUILD_VERSION && \
    rm -f .npmrc

# Stage 2: Nginx configuration stage
FROM myorg/docker-base:latest AS nginx-conf

# Stage 3: Final nginx image
FROM nginx:stable-alpine-slim

# Copy the build output and nginx configuration
COPY --from=build /var/www/app/dist/ngx-rsc-app /var/www/app
COPY --from=nginx-conf /etc/nginx/conf.d/app-nginx.conf /etc/nginx/conf.d

# Set ownership and permissions for NGINX directories, files and create the Nginx process ID file
RUN chown -R nginx:nginx /var/www/app /var/cache/nginx /var/log/nginx /etc/nginx \
    && touch /var/run/nginx.pid \
    && chown nginx:nginx /var/run/nginx.pid \
    && rm /etc/nginx/conf.d/default.conf

# Install net-tools to provide network diagnostic tools
RUN apk add --no-cache net-tools

# Set the Nginx user
USER 101

# Run Nginx with the command "nginx -g daemon off;"
CMD ["nginx","-g","daemon off;"]


构建的依赖映像的容器日志不再显示任何curl或libcurl。

相关问题