Containers & Images - Core Concepts | DevOps Material | VisualPath

Containers & Images

In this exercise, we will build a docker image for nodejs app. Will use dockerhub as registry and will run that image on our kubernetes cluster. Check the docker-demo directory. Verify three files shown below.
- Dockerfile
# cat Dockerfile
FROM node:4.6
WORKDIR /app
ADD . /app
RUN npm install
EXPOSE 3000
CMD npm start
- index.js
# cat index.js
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port); });
- package.json
# cat package.json
{
"name": "myapp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node index.js"
},
"engines": {
"node": "^4.6.1"
},
"dependencies": {
"express": "^4.14.0",
"mysql": "^2.10.2"
}
}
Install docker:
Build Image:
Images name should match with your docker hub account/reponame. For example, my account name in docker hub is “visualpath”, so my image name is visualpath/k8s-demo.
• Run image locally and test.
• Test it from the browser
Enter IP address of your vm(kops vm) where your container is running and port number.
• Push Image to Docker hub

First App on Kubernetes

• Let’s run our newly built application on the Kubernetes cluster
• Before we can launch a container, we need to create a POD definition.
• A Pod describes an application running on Kubernetes.
• A can contain one or more tightly coupled containers, that make up the app.
-> Those apps can easily communicate with each other using their local port numbers.
Our app only has one container.
Read pod definition 
• Use kubectl to create pod on cluster
• Useful Kubectl commands
• Executing commands on a container.
For more information about Visualpath, visit www.visualpath.in and follow the company on Facebook and Twitter.

Comments