Docker error after CTRL+C: Cannot kill container - javascript

Please help me with the correct Dockerfile for the NextJS application.
I'm trying to use these example from official repository: https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile.multistage
My Dockerfile:
# Stage 1: Building the code
FROM node:lts-alpine#sha256:5edad160011cc8cfb69d990e9ae1cb2681c0f280178241d58eba05b5bfc34047 AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
ENV NODE_ENV production
RUN npm run build
RUN npm ci --only=production
# Stage 2: And then copy over node_modules, etc from that stage to the smaller base image
FROM node:lts-slim#sha256:f07d995a6b0bb73e3bd8fa42ba328dd0481f4f0a4c0c39008c05d91602bba6f1 as production
USER node
ARG PORT
WORKDIR /app
# COPY package.json next.config.js .env* ./
COPY --chown=node:node --from=builder /app/public ./public
COPY --chown=node:node --from=builder /app/.next ./.next
COPY --chown=node:node --from=builder /app/node_modules ./node_modules
EXPOSE $PORT
CMD ["node_modules/.bin/next", "start"]
My docker-compose.yml:
version: "3"
services:
nextjs:
container_name: redcross-frontend
ports:
- 3000:3000
build:
context: ./
dockerfile: Dockerfile
volumes:
- ./:/usr/src/app
env_file:
- .env.production
After execution docker-compose up I press CTRL+C for stopping it.
As a result in half of all cases I've faced with the error:
enter image description here
I tried to use dumb-init by executing this command: CMD ["dumb-init", "node_modules/.bin/next", "start"].
But I see the same error in half of all cases.

Related

/bin/sh: sequelize: not found in docker AWS elastic beanstalk

I have an api in a docker container mounted in EBS. Suddenly after a new deploy I started getting this error in EBS even after rolling back to a stable deploy (it does work in local):
yarn run v1.22.19
backend | $ sequelize db:migrate
backend | /bin/sh: sequelize: not found
This is my DockerFile:
FROM node:16-alpine
WORKDIR /app
COPY /app/package.json .
COPY /app/yarn.lock .
RUN yarn install
COPY /app .
COPY ./docker/production/node/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start
CMD [ "/start" ]
The start script:
#!/bin/sh
set -o errexit
set -o pipefail
set -o nounset
yarn db:migrate
yarn start
and the docker-compose.yml file:
version: '3.9'
volumes:
node_modules: {}
services:
nginx:
image: nginx
container_name: nginx
ports:
- "80:80"
volumes:
- ./docker/production/nginx:/etc/nginx/conf.d
depends_on:
- app
links:
- app
app:
build:
context: .
dockerfile: ./docker/production/node/Dockerfile
container_name: tralud_backend
restart: on-failure
volumes:
- ./app:/app
- node_modules:/app/node_modules
env_file:
- .env
ports:
- "3000:3000"
I tried running the same code version locally and it does work, it seems that the build it's being done properly.
I tried creating an new EBS env with the the old stable deploy and it does work, but then I start getting the same error once I try to install new dependencies (cors module).

Docker can't find index.html when dockerizing react app

I am pretty new to Docker and I want to dockerize my react app, the index.html file is under my public folder in the react project. When I run the docker image, it fails and gives me an error stating that the index.html file is missing.
The error:
flash#0.1.0 start
react-scripts start
Could not find a required file. Name: index.html Searched in:
/app/public npm notice npm notice New minor version of npm available!
8.11.0 -> 8.19.2 npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.19.2 npm notice Run npm install -g npm#8.19.2 to update! npm notice
Below is the code of my Dockerfile:
FROM node:lts-alpine3.14 as build
RUN apk update && \
apk upgrade && \
apk add --no-cache bash git openssh
RUN mkdir /app
WORKDIR /app
COPY package.json .
RUN npm install -g --force npm#latest typescript#latest yarn#latest
RUN npm install
COPY . ./
RUN npm run build
# ---------------
FROM node:lts-alpine3.14
RUN mkdir -p /app/build
RUN apk update && \
apk upgrade && \
apk add git
WORKDIR /app
COPY --from=build /app/package.json .
RUN yarn install --production
COPY --from=build . .
EXPOSE 3000
EXPOSE 3001
ENV SERVER_PORT=3000
ENV API_PORT=3001
ENV NODE_ENV production
CMD ["npm", "start"]
Try to attach the shell to the container with
docker exec -it CONTAINER_NAME bash
and see where is index.html file and where you need to copy it

Dockerfile COPY package.json ./ works on local correctly but fails on gitlab pipeline

File Directory
Image
Dockerfile
FROM node:16
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . .
ENV PORT=5000
EXPOSE 5000
CMD [ "npm", "run", "dev" ]
running docker file locally
Login Succeeded
$ docker build -t $CI_DOCKER_REPO:$CI_COMMIT_SHORT_SHA -f ./cronTest/Dockerfile .
Step 1/9 : FROM node:16
---> e90654c39524
Step 2/9 : WORKDIR /app
---> Using cache
---> 4ffb8744c0c4
Step 3/9 : RUN ls
---> Running in 992c3cd680f3
Removing intermediate container 992c3cd680f3
---> 0124eea0f9e9
Step 4/9 : COPY package.json ./
COPY failed: file not found in build context or excluded by .dockerignore: stat package.json: file does not exist
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
Even though the same file is used can anyone check this if something is wrong with my dockerfile
The local build and the pipeline build are launching from different paths, but both are provided with the same . relative build context, which means they resolve to different paths.
To emulate the local build, supply the equivalent "build context" paramater
docker build -t $CI_DOCKER_REPO:$CI_COMMIT_SHORT_SHA \
-f ./cronTest/Dockerfile \
./crontTest
Or move into the same directory
cd cronTest
docker build -t $CI_DOCKER_REPO:$CI_COMMIT_SHORT_SHA \
-f Dockerfile \
.
update to the following, but can't help much further without full context of structure
COPY ./package.json ./

How to deal with Exec format error in docker-compose

I tried to build server and db through docker
Here is my docker-compose.yml
version: '3'
services:
api-server:
build: ./api
links:
- 'db'
ports:
- '3000:3000'
volumes:
- ./api:/src
- ./src/node_modules
tty: true
container_name: api-server
db:
build:
context: .
dockerfile: ./db/Dockerfile
restart: always
hostname: db
environment:
MYSQL_ROOT_PASSWORD: test
MYSQL_USER: root
MYSQL_PASSWORD: test
MYSQL_DATABASE: db
volumes:
- './db:/config'
ports:
- 3306:3306
container_name: db
Here is my Dockerfile
FROM node:alpine
WORKDIR /src
COPY . .
RUN rm -rf /src/node_modules
RUN rm -rf /src/package-lock.json
RUN yarn install
CMD yarn start:dev
After set up servers,I tried to access. but following error occured
Error: Error loading shared library /src/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: Exec format error
I wonder where is the problem.
And How to fix it.
If someone has opinion,please let me know.
Thanks
For everybody looking for an solution like me, the solution for me was adding a .dockerignore file with the following content:
.dockerignore
node_modules
My Dockerfile looks like this:
FROM node:14-alpine as development
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
Adding the .dockerignore-file prevents the COPY . .-command from copying the node_modules-folder and fixes the issue with bcrypt not loading.

Docker Image layers and ENTRYPOINT sequence

I have the following dockerfile
FROM maven:3.3.3-jdk-8
#install node
RUN apt-get update
RUN apt-get -qq update
RUN apt-get install -y nodejs npm
# TODO could uninstall some build dependencies
RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
# Install packages for envsubst
RUN apt-get update && apt-get upgrade -y --force-yes && rm -rf /var/lib/apt/lists/*;
RUN apt-get update
RUN apt-get install -y gettext-base
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# cache package.json and node_modules to speed up builds
ADD src src
ADD package.json package.json
ADD node_modules node_modules
ADD pom.xml pom.xml
ADD Gruntfile.js Gruntfile.js
Add gulpfile.js gulpfile.js
ADD settings.xml settings.xml
# Substitute dependencies from environment variables
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8000
Here is the entrypoint script
#!/bin/sh
envsubst < "/usr/src/app/src/js/envapp.js" > "/usr/src/app/src/js/app.js"
mvn clean install -DskipTests -s settings.xml
npm start
Note that the line envsubst < "/usr/src/app/src/js/envapp.js" > "/usr/src/app/src/js/app.js" reads the environment and updates the app.js file
I have confirmed that the file is updated by sshing into the container and opening the file
However when I open the app in the browser it appears that it is still reading the old value of the app.js file.
After a lot of debugging I feel that haveing the npm start command still reads an old layer in the docker file. Is there a way that the new changes are picked up in the `npm start line?
I also tried having npm start as an argument to ENTRYPOINT but still have the same effect. Any ideas on what might be wrong?
I also tried forking the image so I copy the files in one image and use this as a base image for the image that does the environment manipultion
But still have the same problem
Here is how I run the docker container
docker run -e "ENVVARIABLE=VALUE" -i <image-name>

Categories

Resources