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.


  • Why PHP-FPM prefixes a warning when writing to stdout?
  • docker with btrfs ubuntu
  • Copy file from local machine to docker
  • Passing a command with arguments as a string to docker run
  • Deploy Ansible project which include a docker-compose.yml
  • How to apply new logrotate config for syslog, without restarting the system?
  • # 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?

  • Docker: input from web UI user to Docker run Python interpreter
  • Connect to Mysql on localhost from docker container
  • Should I use user-secrets or environment variables with docker
  • Can't change PHP variables in Joomla docker official container
  • How to make odoo read admin_passwd from file?
  • Disk management (cleanup) in a stopped docker container
  • 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.