I am working on a Docker setup for a Node.js application that involves a multi-stage build and uses Sequelize for database migrations. However, I’m facing issues with script execution and volume mounting, leading to failures when the Docker container starts.
Environment Details:
- Dockerfile:
FROM node:14
ARG ENVIRONMENT_NAME
ARG BUILD_NAME
RUN mkdir -p /app-build
ADD . /app-build
WORKDIR /app-build
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn --frozen-lockfile
RUN yarn
RUN yarn build:$BUILD_NAME
FROM node:14-alpine
ARG ENVIRONMENT_NAME
ARG BUILD_NAME
RUN mkdir -p /dist
RUN apk add yarn
RUN yarn global add [email protected]
RUN yarn add shelljs bull dotenv pg [email protected] nyc
ADD scripts/e2etest.sh /
ADD package.json /
ADD . /
COPY --from=0 /app-build/dist ./dist
CMD ["sh", "./e2etest.sh"]
EXPOSE 9010
- Docker Compose:
version: '3'
services:
db_postgres:
image: postgres
ports:
- 5432:5432
restart: always
env_file:
- .env.docker
networks:
- keploy-network
redis:
image: 'redis:alpine'
ports:
- '6379:6379'
command: ['redis-server', '--bind', 'redis', '--port', '6379']
networks:
- keploy-network
app:
container_name: custom_app
build:
context: .
args:
ENVIRONMENT_NAME: .docker
BUILD_NAME: docker
restart: always
depends_on:
- db_postgres
- redis
ports:
- 9010:9010
env_file:
- ./.env.docker
networks:
- keploy-network
volumes:
- /Users/shivamsouravjha/samples-typescript/node-express-graphql-template/.nyc_output:/dist/.nyc_output
networks:
keploy-network:
external: true
- e2etest.sh Script:
#!/bin/sh
set -a . ".env$ENVIRONMENT_NAME" set +a
sleep 10
echo $BUILD_NAME
if [ "$BUILD_NAME" == "local" ]
then
npx sequelize-cli db:drop
npx sequelize-cli db:create
fi
echo $LD_PRELOAD
npx sequelize-cli db:migrate
# Seed data for local builds
if [ "$BUILD_NAME" == "local" ]
then
for file in seeders/*
do
npx sequelize-cli db:seed --seed $file
done
fi
yarn e2etets
# docker cp custom_app:/app-build/dist/nyc_output ./nyc_output_host
The question I’ve is Why might the /dist/.nyc_output directory be locked or busy in this Docker setup?
I get the error of
I’m looking for a fix on the volume mounting, so that the nyc output can be copied from docker image to host machine
2