advanced/docker in Production/README.md
in this artical i'm going to show you the better way to deploy our production web services,in basically we are going to see technique of running multiple production container using docker. when you do dockering in day to day work than you can come across with docker compose really docker is magical tool !! We are gifted with tools in this modern era and we should utilize them to deliver services seamlessly.
In old approach, these pieces are installed on a VPS.
1.Application Server (Node JS, Java or Python)
2.Proxy Server (Apache, Nginx)
3.Cache Server (Redis, Memcached)
4.Database Server(MySQL, PostgreSQL and MongoDB etc)
in the old approad not preffered bacause of cutomation is taking place everyone using CI/CD deployemnet.we can also capture a snapshot of given eniroment to reduce risk into wrong set of condition deploying services.
according to microservice, the tightly coupled logiic and deploy them separately. its means in above diagram the every application server in more independent and talk via HTTP or RPC. but its doesn't mean you need to choose X number of VPS instane to run services.
but container provide nice way to simulate and and isolation feature within same machine or server.its era of containerization If you wrote a service and planning to deploy it on AWS EC2 or any cloud VPS, don’t deploy your stuff as a single big chunk. Instead, run that distributed code in the containers. We are going to see how to containerize our deployment using Docker and Docker Compose.
lets see in practical. Steps to follow:
Clone the Repository:
git clone https://github.com/sangam14/web_services.git
Change directory to dockerapp1 as shown below:
cd webservices
Bringing up app using Docker Compose:
docker-compose up
for PWD click on port you will get health check page
health check by curl
$ curl http://localhost/api/v1/healthcheck
"2018-11-01T03:26:07.605Z/"
If you see, we are creating a simple express service with a health check endpoint.
https://github.com/sangam14/web_services/blob/master/app/server.js
we are added nginx configuration file.
https://github.com/sangam14/web_services/blob/master/nginx/default.conf
upstream service {
server app:8080;
}
nginx and app both are bridged using mynetwork, one can access another by the service name. So DNS is already taken care by docker. If this privilege is not available, we need to hard code IP in Nginx configuration file or assign a static IP from the subnet in the docker-compose.yam file. This is a wonderful thing about docker networking.
version: "2"
services:
nginx:
build: ./nginx
ports:
- "80:80"
networks:
- mynetwork
app:
build: ./app
networks:
- mynetwork
expose:
- 8080
networks:
mynetwork:
driver: bridge
By default, all the containers we create will fall under the same Internal IP range(Subnet). Docker networking allows us to create custom networks with additional properties like automatic DNS resolution etc.
In the above YAML file, we are creating a network called mynetwork. The services(containers) app and nginx will lie in the same subnet and can communicate to each other without the need of exposing the web service container to the outside world. In this way, we can make a single entry point to our web service that is through the Nginx service. If anyone tries to access app service directly they cannot do it because it is hidden. This actually secures our application.
Sangam biradar - [email protected] -www.codexplus.in