AWS ECS
1. create EC2 instance for docker local image creation and install docker on that.
2. create user and folders on it, assign S3FULL access and ECS role to EC2 machine
#IAM policy AmazonEC2ContainerRegistryFullAccess
#!/bin/bash
#useradd xxxx-user
#su - xxxx-user
mkdir Preventivecontrols
cd Preventivecontrols/
mkdir pc-tomcat-dinesh Preventive-control-UAT Preventive-control-DEV Preventive-control-PROD
cd pc-tomcat-dinesh/
aws s3 cp s3://man-xxxxxxxxxxxxx-user/arunk/war/local_docker_deploy_web.sh .
aws s3 cp s3://man-xxxxxxxxxxxxx-user/arunk/war/Dockerfile .
#####################################
Deployment to Dev(local)
---------------------------------------------------
Dockerfile
FROM tomcat:8.0-alpine
LABEL maintainer="deepak@softwareyoga.com"
ADD PreventiveControl.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["catalina.sh", "run"]
......................................................................................
sh local_docker_deploy_web.sh v1
###########Assigning standard docker variables#########
DATE_TIME=`date "+%m-%d-%y%"`
IMAGE_NAME="preventivecontrol"
PORT="9095"
CONTAINER_NAME="preventive-control"
########## Remove old container##########
$1
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
######## Rename old WAR file #########
#mv /home/aexp-user/Preventivecontrols/Preventive-control-LOCAL/PreventiveControl.war PreventiveControl$DATE_TIME.war
######## COPY AtulWeb WAR FILE ##########
aws s3 cp s3://man-420244912485-user/arunk/war/sample.war PreventiveControl.war
###### Build the image with latest WAR FILE #######
docker build -t $IMAGE_NAME:$1 .
#######Run the container from the build########
docker run -d -p $PORT:8080 --name $CONTAINER_NAME $IMAGE_NAME:$1
-------------------------------------------
http://3.133.7.49:9095/PreventiveControl/
aws ecr create-repository --repository-name preventive-control-uat --region us-east-2
#Next tagging a repository
docker tag preventivecontrol:v1 776499148221.dkr.ecr.us-east-2.amazonaws.com/preventive-control-uat
#login 1st login with aws configure from EC2 machine
aws ecr get-login-password | docker login --username AWS --password-stdin 776499148221.dkr.ecr.us-east-2.amazonaws.com/preventive-control-uat
#to push docker image to ecr
docker push 776499148221.dkr.ecr.us-east-2.amazonaws.com/preventive-control-uat:latest
#To delete
#aws ecr delete-repository --repository-name preventive-control-uat --region region --force
Deployment to UAT(ECS)
--------------------------------------------------------------------------------
Dockerfile
Dockerfile
FROM tomcat:8.0-alpineLABEL maintainer="deepak@softwareyoga.com"
ADD PreventiveControl.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["catalina.sh", "run"]
---------------------------------------------------------------------------------------------
sh docal_docker_deploy_web v1 ---UAT file
#/bin/bash
DATE_TIME=`date "+%m-%d-%y"`
IMAGE_NAME="776499148221.dkr.ecr.us-east-2.amazonaws.com/preventive-control-uat"
mv /home/aexp-user/Preventivecontrols/Preventive-control-UAT/PreventiveControl.war PreventiveControl.war.$DATE_TIME
cp /home/aexp-user/Preventivecontrols/pc-tomcat-dinesh/PreventiveControl.war /home/aexp-user/Preventivecontrols/Preventive-control-UAT/
docker build -t $IMAGE_NAME:$1 .
docker push $IMAGE_NAME:$1
-------------------------------------------------------------------------------------------------
After pushing image to ECR, Now go to Task definition,
Create Task Defination
and create-Done
Now go to Cluster
create cluster - cloudprint-ec2
go to Run new Task
If get any error you can check as below:
If container running succesfully can see below:
Create Service:
(Before create service you should have load-Balancer)
but in case if something happen and task die, there is no machnisiam to comback automatically, if you say high availablity, so in order to achive this We go and create a service
No comments:
Post a Comment