Node.js Koa app and CouchDB in single container

I have a koa.js app which I want to run in a docker container. This loa app requires couchdb to run, which I want to ship in the same container. I know this is not best practise but it is indeed the best way for my users to get started.


  • docker command is showing nothing in centos7
  • How can I attach VS Code to a node process running in a docker container
  • How to know server's IP address where jenkins deploys and builds code
  • Docker volumes-from blank, from network share
  • How can I define a build directory if a required Docker images doesn't exist
  • Localhost connection refused in Docker development environment
  • # DOCKER-VERSION 1.2.0
    FROM centos:centos6
    # Enable EPEL for CouchDB and Node.js
    RUN yum -y update; yum clean all
    RUN yum -y install epel-release; yum clean all
    RUN yum -y install tar
    # Install Node.js and CouchDB
    RUN yum -y install couchdb; yum clean all
    RUN service couchdb start
    RUN yum install -y nodejs
    RUN yum install -y npm
    # Bundle app source
    ADD . .
    # Install app dependencies
    RUN npm install
    RUN npm install -g n
    RUN n 0.11.12
    # Expose port and run
    EXPOSE 8080
    CMD ["npm", "start"]

    which works fine, app gets launched but it can’t connect to the couchdb. throwing in a

    RUN service couchdb start

    response with OK, so it seems to work, but

    curl -X GET

    response with

    curl: (7) couldn't connect to host

    same for the koa.js app:

    error: error stack=Error: connect ECONNREFUSED
    at exports._errnoException (util.js:745:11)
    at Object.afterConnect [as oncomplete] (net.js:995:19), code=ECONNREFUSED, errno=ECONNREFUSED, syscall=connect

    someone knows what I am missing or what I am doing wrong?

  • Boot2Docker for OS X fails to start
  • Jenkins and docker-compose
  • Docker Rest Apis using node.js
  • Invoke Docker Remote API using Java
  • Duplicating docker container for debugging
  • How does one specify a particular cipher suite for a nginx docker instance?
  • One Solution collect form web for “Node.js Koa app and CouchDB in single container”

    The only command that is run when you start this image is what is in the CMD line. Every line before that creates a read only, non-running image. Thus, the line RUN service couchdb start will start the service for an instant, until it is marked as successful, then docker will stop that image, save it, and move on to the next line. The “running” state of the service doesn’t persist.

    It is a common misconception, and one I fell into when I started.

    The three options, top being fastest yet most hacky, and last being most work but most proper:

    1. Put service couchdb start && npm start as your CMD line.
    2. Create a script, do all the “running” that you need to do in there, and call that as your CMD line
    3. Use a service designed to do this stuff for you, supervisord is often recommended.

    This is a common issue, so if you have a read through google results searching for “start service in docker” you’ll see more information around the subject.

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