-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
skumar064c
authored and
skumar064c
committed
Apr 4, 2017
0 parents
commit 8bf718b
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}/`); | ||
}); |