0% found this document useful (0 votes)
10 views12 pages

w8,9 CND Copy k4

Uploaded by

adepunetha5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

w8,9 CND Copy k4

Uploaded by

adepunetha5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

WEEK-8

Name B.Divya
A. Somanshu Dev
Roll No. 22R21A05L2
22R21A05K4
Year of Study III B.Tech I SEM CSE-D
Date 27/11/2024
PROBLEM STATEMENT: To Create a Docker image and push Docker image into
AWS ECR
Objective: Create a Docker image and push Docker image into AWS ECR.
Requirement: Docker tool ,Internet
Theory:
1. Docker Login

Go to hub.docker.com/signup and create your account. To connect your system with


your Docker account, execute docker login in the terminal.
You will see Login succeeded prompted in the terminal.

How to Dockerize Your Project


By Dockerize, I mean setting up your existing project with Docker and containerizing it.
Create a file named Dockerfile without any extension in the root of your project
directory. It contains the code required to build a Docker image and run the
dockerized app as a container.
If you are using VS Code, the Docker extension will come in handy.
How to Configure the Dockerfile
As a bare minimum configuration, paste the following code in the Dockerfile.
FROM node:12.17.0
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
ENV PORT=3000
EXPOSE 3000
CMD [ "npm", "start" ]

Before understanding these instructions, create a .dockerignore file and add


node_modules in it. It works the same as .gitignore.

Step 2: Create a Docker Image


You use the docker build command to create a build of Docker image. There are a bunch
of parameters we can pass with the command. But one we are going to use here is -t.
This gives your image a name tag which makes it easy to remember as well as access.
There is no standardized way to name your image, but normally you would see this:
Docker user name followed by a slash (/) and then version number separated by a
colon(:).
docker build -t <name-tag> .
The second argument is the location of the Dockerfile. Since ours are in the same
directory, we can put a period(.).
When you run the command, you will see that steps are being executed in the same
order as they are written in the Dockerfile. Once done, it will prompt Successfully built
<baseID> in the terminal.
You can use baseID to access the particular Docker image instead of using its name tag.
For the time being, let's run our Docker image in our local system
docker run -p 3000:3000 <name-tag>
Step 3: Login AWS account:

Step 4: Required IAM permisions for puhing an docker image:


Step 5: Create the AWS ECR repository
In the AWS console go to the AWS ECR page. Click the “Create repository” button.

AWS ECR list all repositories page


Then choose visibility of your repository. I leave it as “private”, so it will be managed by
IAM and repository policy permissions and won't be accessible to the public. Then fill
up the name and click Create a repository on the bottom of the page.

Create AWS ECR repository form


An empty repository has been created!

The newly created AWS ECR repository

Step 6: Prepare the image to be pushed.


In this example, I will push the image of a simple Node.js app that listens on port 8080
and displays its host/container name. The source code you can check here. The root
directory has a Dockerfile. We will use it to build an image. Before pushing the image to
the repository we need to tag it with the repository URL.
Step 7: Authenticate the Docker CLI to your AWS ECR Now
we need to authenticate the Docker CLI to AWS ECR. #
Command
$aws ecr get-login-password --region <REPOSITORY_REGION> | docker login -- username
AWS --password-stdin <REPOSITORY_URI>
For this command to execute successfully you have to have your AWS credentials stored in
the credentials file and your IAM principal has to have the necessary permission.

Step 8: Push the image to AWS ECR


To push the image to the AWS ECR we will execute the following command:

The result of the executed push image command Now


the image is in my repository created in step 1.

The image in the repository


WEEK-9
Name B.Divya
A. Somanshu Dev
Roll No. 22R21A05L2
22R21A05K4
Year of Study III B.Tech I SEM CSE-D
Date 27/11/2024
PROBLEM STATEMENT: Create Repositories, Cloning, and Pushing Code Changes
using AWSCodeCommit

Steps to be followed:

1. Goto Aws portal and create an IAM user with administrative permissions.

2. Goto AWS portal and search for Code Commit.

3. Create a repository named: my-webapp and hit create.

4. After creating the repository, we will go inside it and clone it in local system, by
clicking Clone URL > Clone HTTPS.

A. Somanshu Dev
22R21A05K4
5. Now, Goto your command line in local system and type,

Git clone <URL_copied_from_repo> and it will ask username and password.

Here you need to give the username and password of IAM user that you have created.

6. And, it will clone an empty repository. Just run “ls -l” command and you will find out
an empty directory named “my-webpage”

7. Now, we will push some code in the repository.

8. Copy all the files that you have got from the link “https://github.com/chxtan/my
webpage” and paste inside the folder “my-webapp” that created by cloning the empty
repository.

9. Now with command line, browse inside the my-webpage folder and do “ls”, it will
list down all the files inside.
10. Run command “git status” and it will show that all the files are untracked.

11. We will use the “git add .” command to track all the files that were untracked.

12. Now, we will do the first commit as, “git commit -m “first commit””

13. We made a commit; it was made locally. Still we need to push our changes to our
repository.

14. For that we will use command: “git push”


15. And, the code will be uploaded to the AWS repository.

16. Now, we will go to index.html file and modify the content inside.

Suppose, we will change “Congratulations V1” to “Congratulations V2”,

17. And in CMD, we will run “git status” again and the index file will be in untracked
category.
18. To make the file tracked, we will run “git add .\index.html”, and the file will be
tracked again.

19. And now we will push the file again, with “git push” command.

20. We can view the latest commits on AWS portal itself.

21. We can create a new branch by running, “git checkout -b my-feature”.


22. Now we will made some changes again to the “index.html” file as “Congratulations
V2” to “Congratulation V3”.

23. Run “git status” command and “index.html” will be in untracked mode. Keep in my
mind that we are in “my-feature” branch.

24. Move that file in tracked mode and run the command “git push –set-upstream origin
my-feature”.

25. Here, in AWS portal, both the branches will be pushed.

26. Now, we need to add the new feature added that is in “my-feature” branch, for that
we will “create pull request”.
27. Compare the both branches.

28. And create a pull request.

29. Reviewer will Merge this pull request.

30. And your new feature will be merge in master branch.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy