skip to Main Content

I have a base image called docker-base which has a Dockerfile as shown below:

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

It uses the latest node version and the image is built using debain bookworm as shown below when I run the container from the image

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/"

But it shows version of curl and libcurl as below

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)

I tried updating it to version (>=8.0), but as per the official document the latest curl version in debian packages which nginx uses is 7.88.1.

I tried removing the curl and libcurl from the base image by adding the followuing in the above Dockerfile.

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

But when I built my dependent image using the base and ran the container it keeps restarting.
My dependent image Dockerfile as below:

# 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

This is the error from the container logs of the dependendent image that was built

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

Any idea why its throwing this error and possible resolution? Also, is there a better way to remove the the existing curl and libcurl and also keep the container healthy? Or update it to a version >=8.0?

2

Answers


  1. Chosen as BEST ANSWER

    The solution that worked was using nginx based on alpine image, which doesn't have curl and libcurl packages installed. I retained the nginx configurations from myorg/docker-base. Here is the complete solution:

    Dockerfile of my docker-base image

    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 of my dependent image

    # 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;"]
    

    The container logs of the dependent image that was built, doesn't show any curl or libcurl anymore.


  2. Errm… Shouldn’t you have either a docker ENTRYPOINT or docker CMD instruction somewhere in your docker file? How did it decide /docker-entrypoint.sh was your entrypoint, and where do you copy that file into the container?

    In any case, for the exec() system call to be able to execute a shell script it needs (a) to have the x bit set. i.e. chmod +x docker-entrypoint.sh. (b) it needs to have #!/bin/bash (or whatever shell) at the beginning. That error would indicate that it probably doesn’t.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search