docker images
list imagesdocker rmi IMAGE ID
remove imagedocker pull mhart/alpine-node
download an imagesdocker run --rm nginx
run an imagedocker ps
list running imagesdocker stop CONTAINER ID
- stop a running image
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/
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.