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 docker container still can communicate with outside when i shutdown the iptables
  • Disable docker image being run as daemon (restart always policy)
  • Where execute RUN command from Dockerfile, Host or Intermediate container?
  • Docker with two web application containers
  • How to convert a Dockerfile to a docker compose image?
  • Cant access environment variables in php
  • # 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 container cannot send log to docker ELK stack
  • Docker CMD executable 'not found' - LUA
  • Docker Networking - nginx: [emerg] host not found in upstream
  • How to config apache (installed in server) to run a web app (django) in docker?
  • Docker ADD then RUN
  • Environment variables in Docker
  • 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.