Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
skumar064c authored and skumar064c committed Apr 4, 2017
0 parents commit 8bf718b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# dockerized node server
#

FROM node:6.10.1

MAINTAINER Shiva Chandra Kumar K <ksck23@gmail.com>

RUN mkdir -p /tmp/app

WORKDIR /tmp/app

ADD . /tmp/app

RUN npm install

ENV PORT 8000

EXPOSE $PORT

CMD ["npm", "start"]
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# docker-example
An example Docker image creation from scratch.

### Install Docker Machine

Follow the procedure [here](https://docs.docker.com/machine/install-machine/) to install docker-machine. Machine let's you start virtual hosts using virtual-box (in our case) and run docker on it.

Note: you can run the following natively too. I'm using a virtual host to keep the dev env isolated.

Get some help using :

```sh
$ docker-machine --help
```

### Create a VM (dev) running boot2docker

Let's create a machine (virtual host). Ensure virtual-box is installed and running on your local machine.

```sh
$ docker-machine create --driver virtualbox dev

$ docker-machine env dev (shows the new VM env configuration)

# Copy the project's Dockerfile | package.json | server.js files into the VM.

$ docker-machine scp -r . dev:/home/docker/

$ docker-machine ssh dev (to login into the new VM)

(optional)

$ docker-machine start dev (start the VM)

$ docker-machine stop dev (stop the VM)

$ docker-machine ls (show list of VMs)

$ docker-machine kill dev (kill the VM)

$ docker-machine rm dev (to remove the VM completely)
```

### Getting Started

Once you have ssh into `dev` VM which is a boot2docker image. You should see that `docker` is pre-installed on it. You are ready to start off.

```sh

$ docker build -t ksck23/node .

$ docker run -it --rm --name app ksck23/node
```
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "node-docker-example",
"version": "1.0.0",
"description": "Running example node.js server using docker",
"main": "server.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"node",
"docker"
],
"author": "Shiva Chandra Kumar K <ksck23@gmail.com>",
"license": "MIT"
}
14 changes: 14 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const http = require('http');

const hostname = '0.0.0.0';
const port = process.env.PORT || 8000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});

0 comments on commit 8bf718b

Please sign in to comment.