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

fiei3ece  于 2024-01-06  发布在  Linux
关注(0)|答案(2)|浏览(228)

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

  1. FROM nginx:latest
  2. # Create app directory
  3. WORKDIR /var/www/app
  4. RUN rm /etc/nginx/conf.d/default.conf
  5. # Install app dependencies
  6. COPY app-nginx.conf /etc/nginx/conf.d
  7. COPY motd /etc/motd
  8. RUN chmod 0644 /etc/motd; echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/motd' >> /etc/bash.bashrc
  9. COPY usersessiontimout.sh /etc/profile.d/usersessiontimout.sh
  10. RUN chmod +x /etc/profile.d/usersessiontimout.sh
  11. EXPOSE 8000

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

  1. root@e4f1d0771272:/var/www/app# cat /etc/os-release
  2. PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
  3. NAME="Debian GNU/Linux"
  4. VERSION_ID="12"
  5. VERSION="12 (bookworm)"
  6. VERSION_CODENAME=bookworm
  7. ID=debian
  8. HOME_URL="https://www.debian.org/"
  9. SUPPORT_URL="https://www.debian.org/support"
  10. BUG_REPORT_URL="https://bugs.debian.org/"


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

  1. docker exec e4f1d0771272 dpkg -l | grep curl
  2. ii curl 7.88.1-10+deb12u4 arm64 command line tool for transferring data with URL syntax
  3. 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。

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


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

  1. # Stage 1: Build stage
  2. FROM node:12.3.1-alpine AS build
  3. # Use different mirrors
  4. RUN sed -i -e 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
  5. # Install necessary packages using the 'apk' package manager
  6. RUN apk update && \
  7. apk add --no-cache wget build-base openssl-dev
  8. # Set the source folder
  9. ARG SOURCE_FOLDER="./"
  10. ARG BUILD_VERSION
  11. ARG NPM_TOKEN
  12. # Create app directory
  13. WORKDIR /var/www/app
  14. # Bundle app source
  15. COPY ${SOURCE_FOLDER} .
  16. RUN apk update && apk upgrade && \
  17. apk add --no-cache bash git openssh && \
  18. npm config set unsafe-perm true && \
  19. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc && \
  20. npm i -g @myorg/lsc && \
  21. npm i --quiet --cache=./npm-cache
  22. # Build the application
  23. RUN NODE_OPTIONS=--max_old_space_size=4096 lsc build site --output-hashing all --buildVersion=$BUILD_VERSION && \
  24. rm -f .npmrc
  25. # Stage 2: Final stage
  26. FROM myorg/docker-base
  27. # Copy only the necessary artifacts from the build stage
  28. COPY --from=build /var/www/app/dist/ngx-rsc-app /var/www/app
  29. # Install necessary packages using 'apt-get' package manager
  30. RUN apt-get update
  31. # Switch back to app directory
  32. WORKDIR /var/www/app


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

  1. root@ip:~# docker logs -f 77666b51984a
  2. exec /docker-entrypoint.sh: exec format error
  3. exec /docker-entrypoint.sh: exec format error
  4. exec /docker-entrypoint.sh: exec format error
  5. 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

  1. FROM nginx:latest
  2. # Create app directory
  3. WORKDIR /var/www/app
  4. RUN rm /etc/nginx/conf.d/default.conf
  5. # Install app dependencies
  6. COPY app-nginx.conf /etc/nginx/conf.d
  7. COPY motd /etc/motd
  8. RUN chmod 0644 /etc/motd; echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/motd' >> /etc/bash.bashrc
  9. COPY usersessiontimout.sh /etc/profile.d/usersessiontimout.sh
  10. RUN chmod +x /etc/profile.d/usersessiontimout.sh
  11. EXPOSE 8000

字符串

我的依赖镜像的Dockerfile

  1. # Stage 1: Build stage
  2. FROM node:12.3.1-alpine AS build
  3. # Use different mirrors
  4. RUN sed -i -e 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
  5. # Install necessary packages using the 'apk' package manager
  6. RUN apk update && \
  7. apk add --no-cache wget build-base openssl-dev
  8. # Set the source folder
  9. ARG SOURCE_FOLDER="./"
  10. ARG BUILD_VERSION
  11. ARG NPM_TOKEN
  12. # Create app directory
  13. WORKDIR /var/www/app
  14. # Bundle app source
  15. COPY ${SOURCE_FOLDER} .
  16. RUN apk update && apk upgrade && \
  17. apk add --no-cache bash git openssh && \
  18. npm config set unsafe-perm true && \
  19. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc && \
  20. npm i -g @myorg/lsc && \
  21. npm i --quiet --cache=./npm-cache
  22. # Build the application
  23. RUN NODE_OPTIONS=--max_old_space_size=4096 lsc build site --output-hashing all --buildVersion=$BUILD_VERSION && \
  24. rm -f .npmrc
  25. # Stage 2: Nginx configuration stage
  26. FROM myorg/docker-base:latest AS nginx-conf
  27. # Stage 3: Final nginx image
  28. FROM nginx:stable-alpine-slim
  29. # Copy the build output and nginx configuration
  30. COPY --from=build /var/www/app/dist/ngx-rsc-app /var/www/app
  31. COPY --from=nginx-conf /etc/nginx/conf.d/app-nginx.conf /etc/nginx/conf.d
  32. # Set ownership and permissions for NGINX directories, files and create the Nginx process ID file
  33. RUN chown -R nginx:nginx /var/www/app /var/cache/nginx /var/log/nginx /etc/nginx \
  34. && touch /var/run/nginx.pid \
  35. && chown nginx:nginx /var/run/nginx.pid \
  36. && rm /etc/nginx/conf.d/default.conf
  37. # Install net-tools to provide network diagnostic tools
  38. RUN apk add --no-cache net-tools
  39. # Set the Nginx user
  40. USER 101
  41. # Run Nginx with the command "nginx -g daemon off;"
  42. CMD ["nginx","-g","daemon off;"]


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

展开查看全部

相关问题