Fig up: Cannot find module – docker run works

I’m trying to run fig up with a minimal node app.

(edited: removed volumes from fig.yml)

  • Unable to access docker container from the port mapped by docker
  • Docker and node_modules - put them in a layer, or a volume?
  • Cannot make/remove an entry for the specified session - cron
  • How to keep changes inside a container on the host after a docker build?
  • Docker --link not adding two entries to hosts file
  • Docker bidirectional communication between containers
  • 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 proceeds as expected. fig up fails with:

    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 don’t understand is that I can run the server in a container (that fig built) without fig:

    $ 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 different about the way fig is trying to run this container?

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

  • How to realize the interaction inside and outside a docker container
  • Rails 5.0.0.1 Atomicity problems?
  • How to get container and image name when using fluentd for docker logging?
  • Expose Docker Ports and Access with DNS for easier Ansible-Access
  • Kubernetes behind explicit proxy
  • How to send http request from Docker to localhost or Virtual Machine
  • One Solution collect form web for “Fig up: Cannot find module – docker run works”

    The difference is the volumes. In the docker run examples you aren’t specifying any volumes, but in your fig.yml you are mounting the current working directory to /src in the container, so the /src that was added during build is masked by the volume, and the node_modules are not available.

    I think you should be fine to remove the volumes from the fig.yml, otherwise you’ll have to run the npm install outside of the container as well.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.