├── Dockerfile ├── Makefile ├── README.md └── config └── supervisord.conf /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:14.04 2 | MAINTAINER Luis Elizondo "lelizondo@gmail.com" 3 | 4 | ENV DEBIAN_FRONTEND noninteractive 5 | 6 | RUN apt-get update 7 | RUN apt-get update --fix-missing 8 | RUN apt-get update --fix-missing 9 | RUN apt-get install -y curl 10 | RUN curl -sL https://deb.nodesource.com/setup | sudo bash - 11 | 12 | RUN apt-get install -y supervisor python nodejs imagemagick git openssl make build-essential gcc ca-certificates 13 | RUN npm install -g npm@latest 14 | RUN npm install -g express-generator bower mocha sinon should assert grunt-cli gulp node-gyp 15 | RUN npm update 16 | RUN apt-get update --fix-missing 17 | RUN mkdir -p /var/log/supervisor 18 | 19 | # Cleanup 20 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 21 | RUN apt-get autoremove -y 22 | 23 | ADD ./config/supervisord.conf /etc/supervisor/conf.d/supervisord-nodejs.conf 24 | 25 | RUN ln -s /usr/bin/nodejs /usr/local/bin/node 26 | 27 | RUN node -v > /etc/nodejs-version 28 | 29 | EXPOSE 3000 30 | 31 | WORKDIR /var/www 32 | 33 | CMD ["/usr/bin/supervisord", "-n"] 34 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CURRENT_DIRECTORY := $(shell pwd) 2 | 3 | build: 4 | @docker build --tag=luis/nodejs $(CURRENT_DIRECTORY) 5 | 6 | build-no-cache: 7 | @docker build --no-cache --tag=luis/nodejs $(CURRENT_DIRECTORY) 8 | 9 | .PHONY: build build-no-cache -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Node.js on Docker with Nginx serving static files 2 | 3 | ## Build 4 | 5 | docker build -t yourname/nodejs . 6 | 7 | ## Create a data only container 8 | 9 | docker run -v /var/files --name APPFILES busybox true 10 | 11 | ## Run 12 | By default, supervisor will start the start.js file, if your application uses a different file to start, change the supervisor file. 13 | 14 | docker run -d -p 8000:80 --volumes-from=APPFILES -v /path/to/app:/var/www --link mongodb:mongodb --link redis:redis luis/nodejs 15 | 16 | ### Show Environment variables 17 | 18 | docker run -itd -p 8000 --name nodejs -v /path/to/app:/var/www --link mongodb:mongodb --link redis:redis luis/nodejs env 19 | 20 | ### With Fig 21 | You can use fig if you want: 22 | 23 | mongodb: 24 | image: luis/mongodb 25 | expose: 26 | - "27017" 27 | volumes_from: DBDATA 28 | web: 29 | build: luis/nodejs 30 | links: 31 | - mongodb:mongodb 32 | expose: 33 | - "80" 34 | volumes: 35 | - "/path/to/app:/var/www" 36 | - "/path/to/store/logs:/var/log/supervisor" 37 | volumes_from: APPFILES 38 | environment: 39 | NODE_ENV: development 40 | 41 | ### Note 42 | Take a look at the nginx.conf file if you need to adapt the static files / directories. -------------------------------------------------------------------------------- /config/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=true 3 | 4 | [program:nodejs] 5 | directory=/var/www 6 | command=npm start 7 | autorestart = true 8 | stderr_logfile=/var/log/supervisor/%(program_name)s.log 9 | stdout_logfile=/dev/fd/1 10 | stdout_logfile_maxbytes=0 11 | redirect_stderr=true 12 | --------------------------------------------------------------------------------