简体   繁体   中英

Commands in Dockerfile not executed while using with docker-compose.yml

I am new to Docker. I have a project with docker-compose.yml and Dockerfile . To build, create, start, and attache to the container, I use the command docker-compose up . But I ran across an issue and this is the issue.

...\app>docker-compose up --force-recreate
Recreating app ... done                                                                                                 Attaching to app
app    |
app    | > app@1.0.0 dev /home/app
app    | > webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
app    |
app    | internal/modules/cjs/loader.js:584
app    |     throw err;
app    |     ^
app    |
app    | Error: Cannot find module '../lib/Server'
app    |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
app    |     at Function.Module._load (internal/modules/cjs/loader.js:508:25)
app    |     at Module.require (internal/modules/cjs/loader.js:637:17)
app    |     at require (internal/modules/cjs/helpers.js:22:18)
app    |     at Object.<anonymous> (/home/app/node_modules/.bin/webpack-dev-server:13:16)
app    |     at Module._compile (internal/modules/cjs/loader.js:701:30)
app    |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
app    |     at Module.load (internal/modules/cjs/loader.js:600:32)
app    |     at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
app    |     at Function.Module._load (internal/modules/cjs/loader.js:531:3)
app    | npm ERR! code ELIFECYCLE
app    | npm ERR! errno 1
app    | npm ERR! app@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
app    | npm ERR! Exit status 1
app    | npm ERR!
app    | npm ERR! Failed at the app@1.0.0 dev script.
app    | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
app    |
app    | npm ERR! A complete log of this run can be found in:
app    | npm ERR!     /root/.npm/_logs/2020-10-07T16_59_56_645Z-debug.log

This is the content of the docker-compose.yml file.

version: "3"

networks:
  web:
    external: true

services:
  app:
    build: .
    image: chatavenue/app
    container_name: app
    command: npm run dev

And this is the content of Dockerfile .

FROM node:8.16.0-alpine
WORKDIR /home/app
COPY package*.json ./
RUN apk --no-cache add --virtual builds-deps build-base python
RUN apk add --no-cache git
RUN npm cache clean --force
RUN npm config set unsafe-perm true
RUN npm config set python /usr/bin/python
RUN npm install -g node-gyp
RUN npm install
COPY . .
RUN echo "I am here"

But I think these commands in Dockerfile seems not being executed. (To test, I wrote the last command RUN echo "I am here" but it is not executed exactly.) That's why the above Cannot find module '../lib/Server' (webpack) issue occurs, I think.

I think the command command: npm run dev in docker-compose.yml is executed and the result is the image above.


Please help me out with these problems. I would appreciate any kind of help.

Thanks and Regards.

In your log it seems like the container is not build. You should run docker-compose up --build --force-recreate in order to recreate the container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM