problems running Docker container in Cypress - docker

The docker container 'will build' but for some reason 'will not run'. I've trying to resolve this but I think I need a fresh pair of eyes on it.
Here is the code:
Docker file:
FROM cypress/included:6.8.0
WORKDIR /app
COPY . /app
RUN npm install
RUN $(npm bin)/ cypress verify
RUN $(npm bin)/cypress
The docker ignore file
node_modules
The docker-compose.yml file
version: '3'
services:
e2e:
image: cypress
build: .
container_name: cypress
command:
npx cypress run
I got the following error message in my terminal
docker-compose -f docker-compose.yml up
Building e2e
[+] Building 293.8s (9/10)
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 36B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/cypress/included:6.8.0 0.0s
=> [1/6] FROM docker.io/cypress/included:6.8.0 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 1.14kB 0.0s
=> CACHED [2/6] WORKDIR /app 0.0s
=> [3/6] COPY . /app 0.1s
=> [4/6] RUN npm install 292.0s
=> ERROR [5/6] RUN $(npm bin)/ cypress verify 1.4s
------
> [5/6] RUN $(npm bin)/ cypress verify:
#9 1.387 /bin/sh: 1: /app/node_modules/.bin/: Permission denied
------
executor failed running [/bin/sh -c $(npm bin)/ cypress verify]: exit code: 126
ERROR: Service 'e2e' failed to build
xxx-MacBook-Air CypressDocker %
#mosaad. I just tried your answer. However I got the following error message
=> ERROR [5/6] RUN $(npm bin)/ cypress verify 1.8s
------
> [5/6] RUN $(npm bin)/ cypress verify:
#9 1.705 /bin/sh: 1: /app/node_modules/.bin/: not found
------
executor failed running [/bin/sh -c $(npm bin)/ cypress verify]: exit code: 127
ERROR: Service 'e2e' failed to build

You should copy after npm install so that node_modules are copied too.
This should work:
FROM cypress/included:6.8.0
WORKDIR /app
RUN npm install
COPY . /app
RUN $(npm bin)/ cypress verify
RUN $(npm bin)/cypress

Many thanks to everyone who took a moment to take a look at my problem. I rewrote the docker-compose.yml file code again and it now works perfectly. If this can help anyone in the future here is the corrected code.
FROM cypress/included:6.8.0
WORKDIR /app
COPY . /app
RUN npm install
RUN $(npm bin)/cypress verify
RUN $(npm bin)/cypress

Related

error An unexpected error occurred: "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz: getaddrinfo EAI_AGAIN registry.yarnpkg.com"

I was following the guide in Docker official guide, Guides->Get started->Part 2: Containerize an application.
git clone https://github.com/docker/getting-started.git
then I created a Dockerfile with content as below:
# syntax=docker/dockerfile:1
FROM node:18-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000
I tried to build it, but an error happened
docker build -t getting-started .
Error information are as follows :
[+] Building 101.8s (12/12) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> resolve image config for docker.io/docker/dockerfile:1 13.7s
=> CACHED docker-image://docker.io/docker/dockerfile:1#sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef1a0dbc 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> [internal] load .dockerignore 0.0s
=> [internal] load metadata for docker.io/library/node:18-alpine 11.9s
=> [1/4] FROM docker.io/library/node:18-alpine#sha256:b3f383c13d71066a4e2380d42f4563ac14ac76b3035a5bea4db84209e14665d5 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 2.49kB 0.0s
=> CACHED [2/4] WORKDIR /app 0.0s
=> CACHED [3/4] COPY . . 0.0s
=> ERROR [4/4] RUN yarn install --production 20.8s
------
> [4/4] RUN yarn install --production:
#10 0.456 yarn install v1.22.19
#10 0.516 [1/4] Resolving packages...
#10 0.689 [2/4] Fetching packages...
#10 5.792 error An unexpected error occurred: "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz: getaddrinfo EAI_AGAIN registry.yarnpkg.com".
#10 5.792 info If you think this is a bug, please open a bug report with the information provided in "/app/yarn-error.log".
#10 5.792 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
------
executor failed running [/bin/sh -c yarn install --production]: exit code: 1
Here is my enviroment :
WIN10 Family Edition 22H2
Docker Desktop 4.15.0 (93002)
I've tried to add command
yarn config set registry http://registry.npm.taobao.org/
in the Dockerfile, but this still happened. The modified Dockerfile is as below:
# syntax=docker/dockerfile:1
FROM node:18-alpine
WORKDIR /app
COPY . .
RUN yarn config set registry http://registry.npm.taobao.org/ && yarn install --production
CMD ["node", "src/index.js"]
EXPOSE 3000
Still didn't fix the error. And I can't find the log file /app/yarn-error.log

runc run failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory

Hi I am creating an image on docker and below are the commands on Dockerfile
FROM node
WORKDIR /app
COPY . /app
RUN npm install
EXPOSE 80
CMD ["node", "server.js"]
When I run the command Docker build . it gives below response
[+] Building 2.0s (8/8) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 138B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:latest 1.0s
=> [internal] load build context 0.0s
=> => transferring context: 295B 0.0s
=> [1/4] FROM docker.io/library/node#sha256:eee19816ad7ae65dbcac037629c355fa4b369d163a660bc9718df8f945e79eeb 0.0s
=> CACHED [2/4] WORKDIR /app 0.0s
=> CACHED [3/4] COPY . /app 0.0s
=> ERROR [4/4] RUN npm install 0.7s
------
** > [4/4] RUN npm install:
#8 0.673 runc run failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory**
Can some please guide
I was expecting the image to be built.
I was facing the same problem in a CI/CD context and it was related to the /var/lib/docker directory.
So you can try these steps (doing so you will temporary loose all your Docker layers and images in your host but can revert the operation if not ok)
Stop your docker service
sudo mv /var/lib/docker /var/lib/_docker
restart the Docker service (if needed, sudo mkdir /var/lib/docker)

Docker error: no such file or directory, open '/package.json' with NestJs application

I'm trying to run a node image(with nestJS application) inside docker but I have this error:
*$ docker compose build
[+] Building 7.3s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 747B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:12.22.4-alpine 6.6s
=> [auth] library/node:pull token for registry-1.docker.io 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 10.04kB 0.0s
=> [development 1/6] FROM docker.io/library/node:12.22.4-alpine#sha256:78be4f61c7a0f00cc9da47e3ba2f1bacf9ba 0.0s
=> CACHED [development 2/6] WORKDIR /project/sawtooth-tuna/backend 0.0s
=> CACHED [development 3/6] COPY package*.json ./ 0.0s
=> CACHED [development 4/6] RUN npm install --only=development 0.0s
=> [development 5/6] COPY . . 0.1s
=> ERROR [development 6/6] RUN cd /project/sawtooth-tuna/backend && npm run build 0.5s
------
> [development 6/6] RUN cd /project/sawtooth-tuna/backend && npm run build:
#0 0.507 npm ERR! code ENOENT
#0 0.508 npm ERR! syscall open
#0 0.508 npm ERR! path /project/sawtooth-tuna/backend/package.json
#0 0.509 npm ERR! errno -2
#0 0.510 npm ERR! enoent ENOENT: no such file or directory, open '/project/sawtooth-tuna/backend/package.json'
#0 0.510 npm ERR! enoent This is related to npm not being able to find a file.
#0 0.510 npm ERR! enoent
#0 0.516
#0 0.516 npm ERR! A complete log of this run can be found in:
#0 0.516 npm ERR! /root/.npm/_logs/2022-05-17T00_58_30_434Z-debug.log
------
failed to solve: executor failed running [/bin/sh -c cd /project/sawtooth-tuna/backend && npm run build]: exit code: 254
I have read all the available posts related to this topic. But no luck -
My docker file
# Download base image
FROM node:12.22.4-alpine As development
# Define Base Directory
WORKDIR /project/sawtooth-tuna/backend
# Copy and restore packages
COPY package*.json ./
RUN npm install --only=development
# Copy all other directories
COPY . .
# Setup base command
RUN npm run build
# # second phase
FROM node:12.22.4-alpine As production
# Declaring working directory
WORKDIR /project/sawtooth-tuna/backend
COPY package*.json ./
RUN npm install --only=production
#Copy build artifacts
COPY --from=builder /project/sawtooth-tuna/backend/dist ./
COPY --from=builder /project/sawtooth-tuna/backend/config ./config
# Start the server
CMD [ "node", "main.js" ]
As I am using docker-compose -
tunachain-backend:
build:
context: .
target: development
dockerfile: ./backend/Dockerfile
image: hyperledger/tunachain-backend
container_name: tunachain-backend
volumes:
- .:/project/sawtooth-tuna/backend
- /project/sawtooth-tuna/backend/node_modules
command: npm run start:dev
ports:
- 3001:3001
- 9229:9229
My project structure -
backend -
NestJs application code
Dockerfile
docker-compose
Any suggestion or any hint(how should I debug the issue). Fairly new with docker ---
Here, the problem is, how and where I was copying my package*.json to the destination folder. As My docker compose file is in the root directory and my Dockerfile is in the backend folder. The copy command should look like backend/package*.json ./.
Also, for debugging the issue. I just find my last successful step image. And sh into it and tried to run the step(which was causing the problem) inside that image, to get more insights.
Hope somone in future will get some help from this.

Docker build for vue project module not found error

I am trying to build a vue app docker image but I keep getting this error
Module not found: Error: Can't resolve './src/main.js' in '/app'
I am using the a multi-stage dockerfile
FROM node:15.4 as build
WORKDIR /app
COPY ./frontend/package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx:1.19
COPY ./frontend/nginx/nginx.conf /etc/nginx/nginx.conf
COPY --from=build /app/dist /usr/share/nginx/html
Here's the script section of the package.json file
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
This is a detailed log of the build process
[+] Building 26.9s (14/16)
=> [internal] load build definition from frontend.dockerfile 0.0s
=> => transferring dockerfile: 293B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/nginx:1.19 2.5s
=> [internal] load metadata for docker.io/library/node:15.4 2.4s
=> [auth] library/node:pull token for registry-1.docker.io 0.0s
=> [auth] library/nginx:pull token for registry-1.docker.io 0.0s
=> [build 1/6] FROM docker.io/library/node:15.4#sha256:a76eb778d162f8fd96138d9ca7dbd14b8916c201775a97d2f2aa22e9f13eb105 0.0s
=> [stage-1 1/3] FROM docker.io/library/nginx:1.19#sha256:df13abe416e37eb3db4722840dd479b00ba193ac6606e7902331dcea50f4f1f2 0.0s
=> [internal] load build context 8.5s
=> => transferring context: 166.03MB 8.4s
=> CACHED [build 2/6] WORKDIR /app 0.0s
=> CACHED [build 3/6] COPY ./frontend/package.json . 0.0s
=> CACHED [build 4/6] RUN npm install 0.0s
=> [build 5/6] COPY . . 7.4s
=> ERROR [build 6/6] RUN npm run build 8.3s
------
> [build 6/6] RUN npm run build:
#14 2.913
#14 2.913 > frontend#0.1.0 build
#14 2.913 > vue-cli-service build
#14 2.913
#14 4.668 All browser targets in the browserslist configuration have supported ES module.
I move the frontend folder from the project to stand alone and I am able to build the image and run a container based on it successfully.
What could possibly be wrong here?
I try to give you some help. First of all I assume your nginx.conf file is located in the upper nginx folder. I see two in your repo. If this is the case you are copying one layer to deep. I suggest to change your file as follows with this order:
FROM node:alpine as build
WORKDIR /app
COPY ./package*.json ./
RUN npm install
COPY "frontend/target/dist" ./
FROM nginx:alpine as production
COPY ./frontend/nginx/nginx.conf /etc/nginx/conf.d/nginx.conf
RUN rm -rf /usr/share/nginx/html/*
COPY --from=build /app /usr/share/nginx/html
What I changed was the layer of the folders you are trying to add and the asterix (*) in package.json. If you are defining a frontend before, you are also searching it in the copied part, which is not existing in the nginx image. Also as you see you only need /app instead of /app/dist. Additional your /etc... config path was wrongly referenced. Give it a shot now. It should work like this with the given information I had.
Add in your .dockerignore file only those lines:
node_modules
dist

Yarn build using rollup hangs in docker build process

I am trying to create a docker image for a svelte application. The svelte application I am using is just the svelte template with TypeScript initiated. I have made no changes to the application itself, my only goal is to serve the svelte application using Docker. I am using yarn berry (v2) as my package manager and rollupjs for the build process. This is my first question so please let me know if something is missing.
I am expecting the image to be built, but when the build process reaches the "yarn build" command, it never completes. It doesn't crash either, but it never completes the build step either. It seems to hang at the bundling step:
=> => # src/main.ts → public/build/bundle.js...
The build command from package.json:
"build": "rollup -c"
My Dockerfile was initially taken from here: https://sveltesociety.dev/recipes/publishing-and-deploying/dockerize-a-svelte-app/. However, I had to make some changes to it for yarn v2 and I found the following stack thread: Using Yarn 2 (Berry) for packaging application in a Docker image. Adding some modifications form that question left me with the following Dockerfile:
WORKDIR /app
COPY package.json ./
RUN yarn set version berry
COPY .yarn ./.yarn
COPY yarn.lock .yarnrc.yml ./
RUN yarn plugin import workspace-tools
RUN yarn workspaces focus -A --production
COPY . ./
RUN yarn build # This is where it gets stuck
FROM nginx:1.19-alpine
COPY --from=build /app/public /usr/share/nginx/html
I run the command docker build -t svelte-image . to build and this is the output I get:
[+] Building 572.6s (16/18)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 34B 0.0s
=> [internal] load metadata for docker.io/library/nginx:1.19-alpine 1.2s
=> [internal] load metadata for docker.io/library/node:12 1.1s
=> CACHED [stage-1 1/2] FROM docker.io/library/nginx:1.19-alpine#sha256:07ab71a2c8e4ecb19a5a5abcfb3a4f175946c001c8af288b1aa766d67b0 0.0s
=> CACHED [build 1/6] FROM docker.io/library/node:12#sha256:cc4adb82efc04b74b9f96326e682ad04be2df84d23e40609802eb6d6c207abde 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 69.58kB 0.0s
=> CACHED [stage-1 2/3] RUN rm /etc/nginx/nginx.conf /etc/nginx/conf.d/default.conf 0.0s
=> CACHED [build 2/10] WORKDIR /app 0.0s
=> CACHED [build 3/10] COPY package.json ./ 0.0s
=> CACHED [build 4/10] RUN yarn set version berry 0.0s
=> [build 5/10] COPY .yarn ./.yarn 0.2s
=> [build 6/10] COPY yarn.lock .yarnrc.yml ./ 0.0s
=> [build 7/10] RUN yarn plugin import workspace-tools 1.5s
=> [build 8/10] RUN yarn workspaces focus -A --production 0.5s
=> [build 9/10] COPY . ./ 0.1s
=> [build 10/10] RUN yarn build 568.9s
=> => # src/main.ts → public/build/bundle.js... # -> Never completes
I have been trying to figure out why the build hangs, but I am unable to find the source of error. It works just fine when building locally with yarn build. Does anyone have any clue as to why it hangs in the bundling process?
I did not figure out what was wrong, but I managed to build the docker image and run it successfully. Here is the working Dockerfile:
FROM node:16 AS build
WORKDIR /app
COPY package.json ./
RUN yarn set version berry
COPY .yarn ./.yarn #
COPY yarn.lock .yarnrc.yml ./
RUN yarn install
# These two lines are from the original example. It did not work to use this,
# but I leave it here to highlight the difference
## RUN yarn plugin import workspace-tools
## RUN yarn workspaces focus -A --production
COPY . ./
RUN yarn build
FROM nginx:1.19-alpine
COPY --from=build /app/public /usr/share/nginx/html

Resources