CICD 배포/CICD 배포

CI - Docker image

김붕어87 2022. 5. 6. 14:33
반응형

CI

 

docker build


[ nginx 어플리케이션으로 docker image을 빌드 합니다. ]

 

1. docker 설치

 

2. index.html 파일 생성

> index.html 파일은 nginx에서 사용할 파일이다.

> nginx docker image 빌드할때 nginx안에 index.html 파일을 복사할 용도로 생성한다.

 

# mkdir build

# cd build

# vi index.html

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p> ekstest - nginx1 </p>

<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

 

3. dockerfile 파일 생성

> dockerfile은 docker image을 생성할 때 어떻게 build할지 정의하는 파일이다.

 

# vi dockerfile

# nginx 이미지를 사용합니다. 뒤에 tag가 없으면 latest 를 사용합니다.
FROM nginx

# RUN index.html 삭제
RUN rm /usr/share/nginx/html/index.html

# host pc 의 index.html를 아래 경로에 복사
COPY ./index.html /usr/share/nginx/html/index.html

# 80 포트 오픈
EXPOSE 80

# container 실행 시 자동으로 실행할 command. nginx 시작함
CMD ["nginx", "-g", "daemon off;"]
 
3. docker build

> docker build은 dockerfile에 정의된 내용으로 docker image을 생성한다.

 

# docker build -t nginx-test:0.1 .
> docker 이름은 nginx-test이며, 버전은 0.1이다. 
 
# docker images;
> docker 이미지가 정상적으로 생성되었는지 확인 
 
# docker run -d --name my-nginx -p 8300:80 nginx-test:0.1
> docker 이미지으로 docker(nginx) 실행

# curl localhost:8300
> docker(nginx) 접근 테스트
 
4. ecr 업로드
> local에 저장된 docker 이미지를 AWS ECR으로 업로드 작업입니다.

 

aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 계정account.dkr.ecr.ap-northeast-2.amazonaws.com

> docker 이미지 업로드 하기전에 AWS ECR 로그인 


docker tag nginx-test:0.1 계정account.dkr.ecr.ap-northeast-2.amazonaws.com/ekstest1:latest

> docker 이미지를 AWS ECR repository 주소에 맞게 변경 / tag 변경


docker push 계정account.dkr.ecr.ap-northeast-2.amazonaws.com/ekstest1:latest

> docker 이미지를 AWS ECR repository에 업로드


5. pod 배포 

kubectl run nginx --image 계정account.dkr.ecr.ap-northeast-2.amazonaws.com/ekstest1:latest --port=80 -ndw

 
6. pod 접근 

curl pod IP:80

 

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p> ekstest - nginx1 </p>

<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

 

 

 

 

 

 

 

 

 

반응형