/
More Docker Stuff

More Docker Stuff

Created account for Voluntarily

      • Currently tied to my (Andrew's) Credit Card.


Sign in as andrew@voluntari.ly

Password in Andrew's last pass.


Select Asia Pacific group: Singapore

https://ap-southeast-1.console.aws.amazon.com/console/home?region=ap-southeast-1#


IAM Users sign in link

https://585172581592.signin.aws.amazon.com/console


585172581592


Create key pair

aws ec2 create-key-pair --key-name VlyKeyPair--query 'KeyMaterial' --output text | out-file -encoding ascii -filepath VlyKeyPair.pem



https://codeburst.io/a-complete-guide-to-deploying-your-web-app-to-amazon-web-service-2854ff6bc399

https://node.university/blog/10067/aws-ecs-containers


Push the Docker image


      1. Retrieve the login command to use to authenticate your Docker client to your registry.
        Use the AWS CLI:
        $(aws ecr get-login --no-include-email --region ap-southeast-1)
        Note: If you receive an "Unknown options: --no-include-email" error when using the AWS CLI, ensure that you have the latest version installed. Learn more 
      2. Build your Docker image using the following command. For information on building a Docker file from scratch see the instructions here . You can skip this step if your image is already built:
        docker build -t vly1-main-repo .
      3. After the build completes, tag your image so you can push the image to this repository:
        docker tag vly1-main-repo:latest 585172581592.dkr.ecr.ap-southeast-1.amazonaws.com/vly1-main-repo:latest
      4. Run the following command to push this image to your newly created AWS repository:
        docker push 585172581592.dkr.ecr.ap-southeast-1.amazonaws.com/vly1-main-repo:latest


$(aws ecr get-login --no-include-email --region ap-southeast-1)

docker build -t vly1-main-repo .

docker tag vly1-main-repo:latest 585172581592.dkr.ecr.ap-southeast-1.amazonaws.com/vly1-main-repo:latest

docker push 585172581592.dkr.ecr.ap-southeast-1.amazonaws.com/vly1-main-repo:latest


https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html#use-ecr


Create the Cluster

Install the ECS Command line

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI_installation.html

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-cli-tutorial-ec2.html


sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-darwin-amd64-latest


Configure the profile

ecs-cli configure profile --profile-name vly1 --access-key XXXXXX --secret-key YYYYYYY


Creates a default configuration

ecs-cli configure --cluster vly-cluster1 --region ap-southeast-1


creates the cluster

ecs-cli up --keypair MY.pem --capability-iam --size 2 --instance-type t2.medium --cluster-config default

ecs-cli up --keypair vly1 --capability-iam --size 2 --instance-type t2.micro--cluster-config default -f


Lots of trouble here getting the keypair file rejected pem does not exist. Cause was creating the keypair in the console, generated new keypair using Aws-cli and all was good.


Change the cluster to t2.micro



Start up the containers

ecs-cli compose --verbose  --file docker-compose-ecs.yml up

ecs-cli compose --verbose  --file docker-compose-ecs-dev.yml up

ecs-cli compose --verbose  --file docker-compose-ecs-atlas.yml up


If you need docker login again

$(aws ecr get-login --no-include-email --region ap-southeast-1)


Stop them

ecs-cli compose --file docker-compose-ecs.yml down



TODO - add logging for cloudwatch.

Start and stop instances


Login to the web server


ssh -i ".ssh/vly1.pem" ec2-user@ec2-54-169-25-99.ap-southeast-1.compute.amazonaws.com

ssh -i ".ssh/vly1.pem" ec2-user@ec2-54-251-128-87.ap-southeast-1.compute.amazonaws.com


Docker images

REPOSITORY                                                         TAG                 IMAGE ID            CREATED             SIZE

585172581592.dkr.ecr.ap-southeast-1.amazonaws.com/vly1-main-repo   latest              ac2a2de2003e        17 hours ago        1.01GB

mongo                                                              latest              a3abd47e8d61        8 days ago          394MB

amazon/amazon-ecs-agent                                            latest              40db8d41ceb2        2 weeks ago         43MB

amazon/amazon-ecs-pause                                            0.1.0               7dab3b9ea1d5        2 weeks ago         954kB


[ec2-user@ip-10-0-1-231 ~]$ docker ps

CONTAINER ID        IMAGE                                                                     COMMAND                  CREATED             STATUS              PORTS                  NAMES

f2c6e2b50f0d        585172581592.dkr.ecr.ap-southeast-1.amazonaws.com/vly1-main-repo:latest   "npm run start:prod"     14 hours ago        Up 14 hours         0.0.0.0:80->8000/tcp   ecs-vly1-3-web-d4d0889191f8c68d7700

467c339836c8        mongo:latest                                                              "docker-entrypoint.s…"   14 hours ago        Up 14 hours         27017/tcp              ecs-vly1-3-db-c2b1e3eebad9aa89c101

8e4e68a6035c        amazon/amazon-ecs-agent:latest                                            "/agent"                 15 hours ago        Up 15 hours                                ecs-agent

[ec2-user@ip-10-0-1-231 ~]$ 


Now log into the container itself

 docker exec -it <name> bash

But there;s not much to see here



Watch the stdout/stderr on the container.

docker container attach ecs-vly1-3-web-d4d0889191f8c68d7700


If server crashes.

docker container restart  ecs-vly1-4-web-d6a9a8f8869bf7ffe601


View the logs:

docker container logs ecs-vly1-4-web-d6a9a8f8869bf7ffe601



2nd instance - what is this doing? Just running EC2 agent.

ssh -i ".ssh/vly1.pem" ec2-user@ec2-54-251-128-87.ap-southeast-1.compute.amazonaws.com 



Run as a service

ecs-cli compose --verbose --file docker-compose-ecs.yml service up




Troubleshooting

Failed to connect to MongoDB.


MongoNetworkError: failed to connect to server [db:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND db db:27017]


      • Check ports on container.
      • http://54.169.25.99:27017/.  Timed out.
      • From mac mongo 54.169.25.99:27017/vly1.
      • Error: couldn't connect to server 54.169.25.99:27017, connection attempt failed: SocketException: Error connecting to 54.169.25.99:27017 :: caused by :: Operation timed out :


      • Enable security group for port 27017.
      • Now can reach mongo 54.169.25.99:27017/vly1.







Task Switch instance types from t2.medium to t2.micro which is free tier.

Related content

AWS Cloud Deployment Infrastructure
AWS Cloud Deployment Infrastructure
More like this
Using Encrypted Env Variables with Cirrus CI
Using Encrypted Env Variables with Cirrus CI
More like this
Archived - AWS Test
Archived - AWS Test
More like this
Deployment Design
Deployment Design
More like this
Using Docker and Docker Compose
Using Docker and Docker Compose
More like this
AWS Admin
More like this