Ashish Pandey
(Business Consultant)
@ashishapy
blog.ashishapy.com
One step towards microservices
Meet-up on 13th March 2016 @ Thoughtworks Pune
Microservices
Services are small - fine-grained to perform a single function.
Services are easy to replace and deploy independently
One service fails, then the whole application does not have to fail
Services can be implemented using different programming languages, databases, hardware and software environment, depending on what fits best
Service
One service managed by two pizza team
Comes with complexity and new challenges
Microservices ...
https://www.flickr.com/photos/psd/13109673843/
Principles of Microservices
Microservices
Modeled around business concept
Small autonomous services
Culture of automation
Highly Observable
Isolate failure
Deploy independently
Decentralize all the things
Hide internal implementation details
Cultural change is the key
Let's start the journey ...
Chapter A:
- Understanding Docker container technologies
- Build a service / app with Docker
Chapter B:
- Docker app with DevOps (CI/CD) automated workflow
We try to achieve today...
The Implementation Breakthrough:
Continuous Deployment, Microservices, and Containers
It's a quest to deploy often and fast, be fully automatic, accomplish zero-downtime, have the ability to rollback, provide constant reliability across environments, be able to scale effortlessly, and create self-healing systems able to recuperate from failures.
Virtual Machines vs Containers
Container
The underlying technology
-
Namespaces:
- The pid namespace
- The net namespace
- The ipc namespace
- The mnt namespace
- The uts namespace
-
Control groups
-
Union file systems
-
Container format
https://docs.docker.com/
Get Started
-
Install Docker Engine on host machine
- Windows or Mac: Docker toolbox
- For quick start use my Digital Ocean referral: https://m.do.co/c/af7efed41ac1 . You will get $10 credit, more than enough for the exercise.
Get Started...
-
Run few basic commands:
- docker info
- docker images
- docker ps
- docker ps -a
Run a software image in a container
- docker run hello-world
- docker run -i -t ubuntu /bin/bash
Re-run commands:
- docker info
- docker images
- docker ps
- docker ps -a
- docker history <ImageId>
Docker hub
Signup on hub.docker.com
Docker image hosting provider
Docker image & Containers
docker images
Image
Image
https://www.docker.com/
docker commit
-
docker commit command saves changes in a container as a new image.
docker commit [options] [container id] [repository:tag]
Docker Containers
- Run container from a image: docker run
- Check running containers: docker ps
- Check all (Running, Stopped, Paused) containers: docker ps -a
- Inspect a container: docker inspect
Docker’s architecture
https://www.docker.com/
docker run
-
Pulls the image
-
Creates a new container
-
Allocates a filesystem and mounts a read-write layer
-
Allocates a network / bridge interface
-
Sets up an IP address
-
Executes a process that you specify
-
Captures and provides application output
https://www.docker.com/
Docker Application
Download Base Image (OS)
Install tools for the app
Download & Install the app
Expose container port to host
1
2
3
4
5
Container default command / Entry point
Demo Node Web App
Node Web Docker App
FROM node:argon
COPY . /usr/src/app & RUN npm install
EXPOSE 8080
1
2
3
4
5
CMD [ "npm", "start" ]
Dockerfile
Dockerfile
A Dockerfile is a configuration file that contains instructions for building a Docker Image
Demo
- Login to host machine & check docker command
- git clone https://github.com/ashishapy/Demo_DockerCI-CD.git
- cd Demo_DockerCI-CD
- docker build -t <username>/demo_dockerci-cd .
- docker images
- docker run -p 80:8080 -d <username>/demo_dockerci-cd
- Enter host machine ip address on browser.
- docker login
- docker push <username>/demo_dockerci-cd
Push to Docker hub
OOO!
We have our own image now!
Can we use it to quickly spin node-web-app?
Run own image
docker run -p 80:8080 -d <username>/demo_dockerci-cd
Achievement unlocked!
Successfully completed Docker basics
Chapter - B
Chapter A:
- Understanding Docker container technologies
- Build a service / app with Docker
Chapter B:
- Docker app with DevOps (CI/CD) automated workflow
DevOps (CI/CD) Workflow
Hub
Automated Workflow
Docker
Cloud
DevOps (CI/CD) Workflow
Hub
Automated Workflow
Docker
Cloud
Continuous Integration
Automated Workflow
Hub
Cloud
Docker
Continuous Integration ...
Automated Workflow
Hub
Cloud
Docker
Docker Hub
- Link your GitHub account with Docker Hub here.
- Go to "Create" -> "Create Automated Build" and create.
- Under "Build Settings" of the repo, uncheck "When active, builds will happen automatically on pushes." option & save.
- Go to "Build Triggers" section, click on "Activate Trigger" button.
- Copy "Trigger URL" generated from previous step.
CircleCI
- Signup with CircleCI using your GitHub account.
- On CircleCI "Dashboard", click on "Add Projects".
- Select your GitHub account then "Build Project" for the repo.
- If all is well then it should successfully pass the project.
- Go to "Project Settings" -> "Environment Variables" & add environment variable as Name: DOCKER_HUB_TRIGGER; Value: curl -H "Content-Type": application/json" --data '{"build": true}' -X POST <Docker_Hub TRIGGER_URL>
- Change circle.yml file to include "deployment" section.
- Push the changes to GitHub repo and watch all auto builds.
Hub
Automated Workflow
Docker
Cloud
Story till now ...
Continuous Deployment
Hub
Automated Workflow
Docker
Cloud
Reference Architecture
Service
- App / Container
Node Cluster
Node
Node
Node
Node
Cloud VM
Cloud VM
Cloud VM
Cloud VM
Docker Cloud
cloud.docker.com
Digital Ocean
Everything have been taken care of by "Docker Cloud"
Check you should have one instance running, created by "Docker Cloud" -> "Node"
Open "Docker Cloud" "Service End Point" on browser
Incremental Change
Push a change to Github, and monitor changes at every step.
Evolving Docker Platform
- Registry: Docker Hub
- Clustering: Docker Swarm
- Orchestration: Docker Compose
- Deploy, manage, and monitor: Docker Universal Control Plane
Also check Kubernetes by Google and Apache Mesos to Manage a cluster of Linux containers
Container as a Service (CaaS)
Future of Docker
Docker on Windows
End of Virtual Machines and only Docker Containers. ex. Joyent Triton
Chip-level assists for Containers