Issue
I try to dockerize a react-native app with expo. And the dockerfile and docker-compose.yml file are in the root folder: dwl-frontend.
So this is the dockerfile:
# pull base image
FROM node:14.13.1-buster-slim
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV
ARG PORT=19006
ENV PORT $PORT
EXPOSE $PORT 19001 19002
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH /home/node/.npm-global/bin:$PATH
RUN npm i --unsafe-perm --allow-root -g npm@latest expo-cli@latest
RUN mkdir /opt/dwl_frontend
WORKDIR /opt/dwl_frontend
ENV PATH /opt/dwl_frontend/.bin:$PATH
COPY package.json yarn.lock ./
RUN yarn
RUN yarn install
WORKDIR /opt/dwl_frontend/app
COPY ./ ./
ENTRYPOINT ["yarn", "run", "web"]
CMD ["web"]
And docker-compose file:
version: "2.4"
services:
dwl_frontend:
build:
context: .
args:
- NODE_ENV=development
environment:
- NODE_ENV=development
tty: true
ports:
- "19006:19006"
- "19001:19001"
- "19002:19002"
healthcheck:
disable: true
But when I do a `docker-compose build`
I get this error:
=> ERROR [dwl_frontend 6/9] RUN yarn 57.2s
[dwl_frontend 6/9] RUN yarn: 0.577 yarn install v1.22.5 0.638 [1/4] Resolving packages... 1.023 [2/4] Fetching packages... 55.75 info [email protected]: The platform "linux" is incompatible with this module. 55.75 info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation. 55.76 error [email protected]: The engine "node" is incompatible with this module. Expected version ">= 16". Got "14.13.1" 55.76 error Found incompatible module. 55.76 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
failed to solve: process "/bin/sh -c yarn" did not complete successfully: exit code: 1
Question: what I have to change?
Solution
The left-hand side of Dockerfile COPY
statements is relative to the build-context directory (except that it can never go to a parent or sibling of that directory). In your example, you specify build: { context: . }
, and you indicate in a comment that all of the source files and the Compose file are in this same directory. In this case you should use .
as the path on the left-hand side of COPY
, or leave it out entirely. (It doesn't matter that the directory happens to be named dwl_frontend
.)
WORKDIR /opt/dwl_frontend # automatically creates the directory
COPY package.json yarn.lock ./ # from the current host directory
RUN yarn install
COPY ./ ./ # current host directory into current image directory
CMD ["yarn", "run", "web"]
Your volumes:
mounts will have the same problem. However, their effect will be to hide everything in the image, which means the image you'll eventually deploy will be completely untested. I'd recommend deleting the volumes:
block entirely.
Answered By - David Maze
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.