Figure: Unable to find module operation - docker

I am trying to run fig up with a minimal node application.

(edited: removed volumes from fig.yml)

fig.yml:

 example: build: . command: node server.js ports: - "4000:4000" links: - postgres postgres: image: postgres 

Dockerfile:

 FROM node ADD . /src WORKDIR /src RUN npm install 

server.coffee:

 express = require 'express' app = express() app.get "/", (req, res) -> res.send "Hello World" server = app.listen 4000, () -> console.log 'Listening on port %d', server.address().port 

fig build continues as expected. fig up crash:

 example_1 | module.js:340 example_1 | throw err; example_1 | ^ example_1 | Error: Cannot find module '/src/server.js' example_1 | at Function.Module._resolveFilename (module.js:338:15) example_1 | at Function.Module._load (module.js:280:25) example_1 | at Function.Module.runMain (module.js:497:10) example_1 | at startup (node.js:119:16) example_1 | at node.js:906:3 

What I do not understand is that I can start the server in the container (which built the pic) without a picture:

 $ docker run -it dockerexample_example /bin/bash root@58d25759047a :/# node /src/server.js Listening on port 4000 

or

 $ docker run -it dockerexample_example Listening on port 4000 

or

 $ docker run -it -p 4000:4000 dockerexample_example Listening on port 4000 

What is the difference between the method that tries to run this container?

These files are available here: https://github.com/skyl/docker-example

+5
source share
1 answer

The difference is volumes . In the docker run examples, you do not specify any volumes, but in your fig.yml you set the current working directory to /src in the container, therefore /src that was added during the build is masked by the volume and node_modules are unavailable.

I think you should be fine to remove volumes from fig.yml , otherwise you will need to run the npm installation outside the container.

+4
source

Source: https://habr.com/ru/post/1206510/


All Articles