Script in docker file not running

  docker, next.js, shell

I need to execute a shell script from within Docker. I am not as proficient in Docker or in scripting as I would like to be. The script has no effect and does not print anything to the screen. I do not believe that it is being called.

What am I doing wrong here?

The script should be run as the entrypoint command.

The Script

#!/usr/bin/env bash
set -Ex

function apply_path {

    echo "Check that we have ENVIRONMENT_VAR vars"
    test -n "$ENVIRONMENT_VAR"

    find /usr/src/app/.next ( -type d -name .git -prune ) -o -type f -print0 | xargs -0 sed -i "s#NEXT_PUBLIC_ENVIRONMENT_VAR#$ENVIRONMENT_VAR#g"
}

apply_path
echo "Starting Nextjs"
exec "[email protected]"

The docker file

ARG NODE_VERSION=14.4.0-alpine

###
# STAGE 1: Base
###
FROM node:$NODE_VERSION as base

ENV NODE_PATH=/src
WORKDIR $NODE_PATH

###
# STAGE 2: Build
###
FROM base as build

COPY package.json package-lock.json .npmrc ./
RUN npm i

COPY . ./

RUN NEXT_PUBLIC_ENVIRONMENT_VAR=BUILD npm run build

# Permisions to execute script
RUN ["chmod", "+x", "./entrypoint.sh"]
ENTRYPOINT ["./entrypoint.sh"]



###
# STAGE 3: Production
###
FROM node:$NODE_VERSION

ENV NODE_PATH=/src
ENV APP_PORT=3000

WORKDIR $NODE_PATH

COPY --from=build $NODE_PATH/.next ./.next
COPY --from=build $NODE_PATH/node_modules ./node_modules
COPY --from=build $NODE_PATH/src ./src
COPY --from=build $NODE_PATH/package.json ./
COPY --from=build $NODE_PATH/.babelrc ./
COPY --from=build $NODE_PATH/LICENSE ./

EXPOSE $APP_PORT

CMD npm start

Source: Docker Questions

LEAVE A COMMENT