Giter Club home page Giter Club logo

my-docker-app's Introduction

Docker 101

Commands

  • docker images list images
  • docker rmi IMAGE ID remove image
  • docker pull mhart/alpine-node download an images
  • docker run --rm nginx run an image
  • docker ps list running images
  • docker stop CONTAINER ID - stop a running image

nodejs

Create a simple node server

// nodejs/index.js
var http = require('http')

var server = http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'})
  res.end('Welcome to Node.js!\n')
})

server.listen(3000)
console.log('Server running at http://127.0.0.1:3000/')

Add a docker file for the node app

# nodejs/Dockerfile
FROM mhart/alpine-node
COPY index.js .
EXPOSE 3000
CMD node index.js

Build and run

docker build -t foo/node .
docker run -d -p 3000:3000 --name node-app foo/node

Then you should be able to hit http://locahost:3000/

nginx

Add nginx config

# nginx/default.conf
server {
  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://app:3000;
  }
}

Add a docker file for nginx

# nginx/Dockerfile
FROM nginx
COPY default.conf /etc/nginx/conf.d/

Build and run

docker build -t foo/nginx .
docker run -p 8000:80 --link node-app:app --name nginx-proxy foo/nginx

Then you should be able to hit nginx at http://locahost:8000/ which proxies through to Node.

my-docker-app's People

Contributors

markbrown4 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.