AWS w Docker Deployment - NischithaCNagaraju/PhotoSite GitHub Wiki
Project R2 - Install Simple PhotoSite in Ruby on Rails use SQLite database ONTO an Amazon EC2 instance
Nischitha Chottanahalli Nagaraju UID : zj2583 Course Number: CS651
Section 1: Introduction and Purpose
This project is categorized into two steps. Initially, we implemented a Photosite web application built in Ruby on Rails using SQLite database. Later, we are deploying the same into an Amazon EC2 instance. This project uses the Model View Controller(MVC) pattern to implement various elements of the application. We are using the same application built in project 1 and it is deployed into the EC2 instance using Docker container.
Youtube URL :: https://youtu.be/hbqpNTBSD-8
The main purpose of this project is to
- learn about creating an EC2 instance
- Installing Ubuntu as the platform for the instance
- Setup Docker container
- Setup ruby and rails on this ubuntu machine using docker container
- Deploy the same and run the PhotoSite application in a web browser.
Section 2: Demonstration of Application working
Login to AWS Console. We can find EC2 option in the All services tab
Launch instance
As conveyed, Launch an Ubuntu server 16.04 LTS (HVM) , SSD Volume type
Choose a Free tier instance type
Leave it to the default setting
Configure security group
Launch the ubuntu instance
Create new key pair
Instance is running
Instance details
SSH to Amazon EC2 from your local machine.
Set Docker in EC2 instance
Docker version
ubuntu@ip-172-31-44-16:~/project$ sudo docker -v Docker version 19.03.6, build 369ce74a3c
Docker info
ubuntu@ip-172-31-44-16:~/project$ sudo docker info Client: Debug Mode: false
Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.6 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd init version: fec3683 Security Options: apparmor seccomp Profile: default Kernel Version: 4.4.0-1101-aws Operating System: Ubuntu 16.04.6 LTS OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 990.6MiB Name: ip-172-31-44-16 ID: PDAY:B3UB:IBX3:ZNL3:ICBR:VYVV:L64E:2QPK:IWWA:NYNT:3OC7:Y6U2 Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
WARNING: No swap limit support ubuntu@ip-172-31-44-16:~/project$
Transfer file from local machine to Amazon EC2 using SCP command
sudo scp -r -i nischitha.pem PhotoSite.zip [email protected]:project
ECDSA key fingerprint is SHA256:j+dqsMw5MzjfG1D6RaHMSOgcfCd4vo6H1TKOSsl8dEY.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-54-146-174-75.compute-1.amazonaws.com,54.146.174.75' (ECDSA) to the list of known hosts.
PhotoSite.zip 99% 29MB 412.2KB/s 01:12
Build Docker container.
Docker file
sudo docker build -t photo-suite .
Deploy the photo site application
Photo site Website :: Main Index page
Section 3: Discussion of anything not working
All the requirements of the project R2 are working completely. Project R1 is working successfully and instance has been created in Amazon EC2 and application is deployed into the instance and running successfully using docker container.
Section 4: Youtube URL
**Section 5 : ** Special Issue 1 : What happens when an instance stops running?
When the instance in AWS EC2 is stopped, all the data present in the instance will be destroyed or not accessible. So we need to freeze the instance. This can be done by following steps
Select the instance which needs to be freezed. Create the image of the instance .
After we create the image of the instance, a new AMI will be created and also a new snapshot will be created.
Stop the instance and Detach the existing volume with the instance. Now go to the snapshots, and In the actions tab: create volume by given name , select the region as instance region.
Delete the old volume which was previously attached to the instance we stopped. Attach the newly created volume to the instance. Select the Instance ID and device same as that of our instance and click attach.
Now start the instance again. Run the Photo site application. Now we are running the application using the backup data which we created.
Cost of this operation is based on the Storage size and the frequency of usage.
**Section 6: ** Special Issue 2: What happens when you reboot an instance and what can you do?
If we stop and start an instance in AWS EC2, the IP address of the instance is changed. So, if we need to connect from a local machine, we need to ssh using a new IP address. We can revert this behavior by using Elastic IP. Elastic IP allows the user to create an IP and associate with the instance. Once the IP is associated, it doesn’t change when we reboot the instance.
Charges for Elastic IPs
Create an Elastic IP
Allocate Elastic IP Address
Associate instance with IP
New Elastic IP is associated with the instance