Docker Community Forums

Share and learn in the Docker community.

Mean Stack Application Failed to Run

docker

(Crissi) #1

The Dockerfile for my application is as follows

                   # Tells the Docker which base image to start.
                   FROM node

                   # Adds files from the host file system into the Docker container.  
                   ADD . /app

                   # Sets the current working directory for subsequent instructions
                   WORKDIR /app

                    RUN npm install
                    RUN npm install -g bower
                    RUN bower install --allow-root
                    RUN npm install -g nodemon

                    #expose a port to allow external access
                    EXPOSE 9000 9030 35729

                    # Start mean application
                    CMD ["nodemon", "server.js"] 

The docker-compose.yml file is as follows

                           web:
                                     build: .
                                     links:
                                                - db
                                      ports:
                                               - "9000:9000"
                                               - "9030:9030"
                                               - "35729:35729"
                                       db:
                                               image: mongo:latest
                                               ports: 
                                                      - "27017:27017"

The error generated while running is as follows:-

               airlineinsurance_db_1 is up-to-date
               Starting airlineinsurance_web_1
               Attaching to airlineinsurance_db_1, airlineinsurance_web_1
               db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten] MongoDB starting :                  pid=1 port=27017 dbpath=/data/db 64-bit host=fcb35780521a
               db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten] db version v3.2.10
               db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten] git  version:               79d9b3ab5ce20f51c272b4411202710a082d0317
                db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten] OpenSSL version:   OpenSSL 1.0.1t  3 May 2016
               db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten] allocator: tcmalloc
               db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten] modules: none
               db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten] build environment:
               db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten]     distmod: debian81
               db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten]     distarch: x86_64
               db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten]     target_arch: x86_64
              db_1   | 2016-11-10T04:14:46.685+0000 I CONTROL  [initandlisten] options: {}
              db_1   | 2016-11-10T04:14:46.706+0000 I STORAGE  [initandlisten] wiredtiger_open       config: create,cache_size=2G,session_max=20000,eviction=     (threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
            db_1   | 2016-11-10T04:14:48.255+0000 I CONTROL  [initandlisten] 
            db_1   | 2016-11-10T04:14:48.255+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
           db_1   | 2016-11-10T04:14:48.255+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
            db_1   | 2016-11-10T04:14:48.255+0000 I CONTROL  [initandlisten] 
            db_1   | 2016-11-10T04:14:48.255+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
            db_1   | 2016-11-10T04:14:48.255+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
     db_1   | 2016-11-10T04:14:48.255+0000 I CONTROL  [initandlisten] 
     db_1   | 2016-11-10T04:14:48.256+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
     db_1   | 2016-11-10T04:14:48.256+0000 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
    db_1   | 2016-11-10T04:14:48.890+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
    db_1   | 2016-11-10T04:14:49.772+0000 I NETWORK  [initandlisten] connection accepted from 172.17.0.1:34243 #1 (1 connection now open)
     db_1   | 2016-11-10T04:45:59.554+0000 I NETWORK  [conn1] end connection 172.17.0.1:34243 (0 connections now open)
     web_1  | [nodemon] 1.11.0
     web_1  | [nodemon] to restart at any time, enter `rs`
      web_1  | [nodemon] watching: *.*
      web_1  | [nodemon] starting `node server.js`
      web_1  | Server running at http://127.0.0.1:9000
      web_1  | Server running at https://127.0.0.1:9030
      web_1  | 
      web_1  | /app/node_modules/mongodb/lib/server.js:261
      web_1  |         process.nextTick(function() { throw err; })
      web_1  |                                       ^
     web_1  | MongoError: failed to connect to server [localhost:27017] on first connect
      web_1  |     at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:313:35)
     web_1  |     at emitOne (events.js:96:13)
     web_1  |     at Pool.emit (events.js:188:7)
     web_1  |     at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:271:12)
    web_1  |     at Connection.g (events.js:291:16)
    web_1  |     at emitTwo (events.js:106:13)
    web_1  |     at Connection.emit (events.js:191:7)
    web_1  |     at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:165:49)
   web_1  |     at Socket.g (events.js:291:16)
   web_1  |     at emitOne (events.js:96:13)
   web_1  |     at Socket.emit (events.js:188:7)
   web_1  |     at emitErrorNT (net.js:1281:8)
   web_1  |     at _combinedTickCallback (internal/process/next_tick.js:74:11)
   web_1  |     at process._tickCallback (internal/process/next_tick.js:98:9)
   web_1  | [nodemon] app crashed - waiting for file changes before starting...

Please help me to resolve these errors…


(Isabeljason) #2

In docker you can’t associate with an other compartment by means of localhost in light of the fact that every holder is independend and has its own particular IP. You should utilize container_name:port. In your case it ought to be db:27017 to interface from your NodeJS application in “web” to the MongoDB in ‘db’.

So it’s not the issue of your Dockerfile. It’s the association URL from your NodeJS application that focuses to localhost rather than db.