Education*
Devops
Architecture
F/B End
B.Chain
Basic
Others
CLOSE
Search For:
Search
BY TAGS
linux
HTTP
golang
flutter
java
fintech
개발환경
kubernetes
network
Docker
devops
database
tutorial
cli
분산시스템
www
블록체인
AWS
system admin
bigdata
보안
금융
msa
mysql
redis
Linux command
dns
javascript
CICD
VPC
FILESYSTEM
S3
NGINX
TCP/IP
ZOOKEEPER
NOSQL
IAC
CLOUD
TERRAFORM
logging
IT용어
Kafka
docker-compose
Dart
ECR에 docker 이미지 push
Recommanded
Free
YOUTUBE Lecture:
<% selectedImage[1] %>
yundream
2023-11-06
2023-11-06
1316
### ECR 이란 ECR은 AWS에서 서비스하는 **Docker Image registry** 다. AWS에 Docker 기반 애플리케이션을 배포하길 원한다면 가장 먼저 고려 할 수 있는 옵션이다. Docker Hub Container Registry, GitHub package Registry, GitLab Container Registry, Sonatype Nexus Repository OSS 등 다양한 registry가 있지만 AWS를 사용한다면 아래와 같은 이유로 ECR을 선택하게 된다. 1. AWS와 통합: AWS 생태계 내에서 원할하게 통합되며, AWS와 상호작용이 용이하다. 이를 통해서 배포 및 관리 프로세스를 간소화하고 보안을 강화할 수 있다. 2. 보안: Docker Image에 대한 액세스 제어및 이미지 스캐닝과 같은 보안 기능을 제공한다. 3. 비용 효율성: 저장한 이미지의 크기 만큼만 비용을 지불하면 된다. 이렇게 구성한 ECR은 EC2(docker), ECS, EKS 등 docker 기반의 다양한 AWS 서비스에서 사용 할 수 있다.  ### ECR 테스트 환경 만들기  #### 도커 설치된 리눅스 운영체제 도커가 설치된 우분투 리눅스에서 테스트 한다. 우분투 리눅스에서의 도커 설치는 [우분투 리눅스에 docker 설치하기](https://www.joinc.co.kr/w/man/12/docker/install) 문서를 참고하자. #### AWS CLI 설치 개인 PC에서 ECR에 접근하기 위해서는 AWS CLI 및 권한 설정이 필요하다. [AWS CLI 설치 및 credential 설정](https://www.joinc.co.kr/w/man/12/aws/cli)문서를 참고해서 CLI와 권한을 설정하자. ECR에 Read/Write 할 수 있는 권한을 가져야 하는데, **AmazonEC2ContainerRegistryFullAccess** 정책을 사용하면 된다. ### ECR 생성  **AWS 관리자 콘솔 > Elastic Container Registry** 로 이동한다. 여기에서 현재 관리 중인 Repository 들을 확인 할 수 있다. **Create repository**를 클릭하면 repository 설정화면으로 넘어갈 수 있다.  **Visibility settings** * Private: 내부에서만 사용가능한 저장소로 **IAM**을 통해서 관리된다. 여기에서는 Private Repository를 만들 것이다. * Public: 공개용 저장소로 외부(인터넷)에서 자유롭게 사용할 수 있다. **Repository name** 이미지 저장소의 이름이다. joinc/hello-world로 설정했다. **Create repository**를 클릭하면 생성된다. ECR 대시보드에서 방금 생성한 Repository를 확인 할 수 있다.  ### Docker Image Push 이제 Docker Image를 저장소에 push 해보자.  **View push commands**를 클릭하면, Image를 Push하기 위한 명령어를 친전하게 가이드한다. 이 가이드에 따라서 스크립트를 만들어서 빌드/푸쉬 하면 된다. 테스트 할 수 있는 예제 코드는 https://github.com/yundream/express_static 에서 다운로드해서 사용 할 수 있다. node.js 예제코드로 Makefile 만 수정하면 테스트 할 수 있다. ```shell $ git clone git@github.com:yundream/express_static.git ```  AWS CLI 환경을 구성했다면, 위의 명령을 그대로 실행하면 된다. 아래는 Makefile을 이용한 실행 예제다. make가 없거나 설치하기 귀찮다면, 그냥 위에 있는 명령을 하나 하나 직접 실행해도 된다. ``` ecr=aws-account-id.dkr.ecr.ap-northeast-2.amazonaws.com/joinc/hello-world imgname=joinc/hello-world ver=0.4 build: docker build -t $(imgname):latest -t $(imgname):$(ver) . deploy: aws ecr get-login-password --region ap-northeast-2 |docker login --username AWS --password-stdin $(ecr) docker tag $(imgname):$(ver) $(ecr):$(ver) docker tag $(imgname):latest $(ecr):latest docker push $(ecr):$(ver) docker push $(ecr):latest ``` Makefile의 ecr은 ECR URI를 복사해서 사용하면 된다. ECR 대시보드에서 URI를 확인 할 수 있다.  이제 make build 명령으로 도커 이미지를 만든다. ``` $ make docker build -t joinc/hello-world:latest -t joinc/hello-world:0.1 . [+] Building 2.6s (9/9) FINISHED docker:default => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 133B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/node:latest 1.5s => [1/4] FROM docker.io/library/node:latest@sha256:0052410af98158173b17a26e0e2a46a3932095ac9a0ded660439a8ffae65b1e3 0.0s => [internal] load build context 0.0s => => transferring context: 1.46MB 0.0s => CACHED [2/4] WORKDIR /app 0.0s => [3/4] COPY . . 0.1s => [4/4] RUN npm install ``` make deploy 명령으로 ECR에 이미지를 push 한다. ``` $ make deploy aws ecr get-login-password --region ap-northeast-2 |docker login --username AWS --password-stdin aws-account-id.dkr.ecr.ap-northeast-2.amazonaws.com/joinc/hello-world WARNING! Your password will be stored unencrypted in /home/yundream/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded docker tag joinc/hello-world:0.1 aws-account-id.dkr.ecr.ap-northeast-2.amazonaws.com/joinc/hello-world:0.1 docker tag joinc/hello-world:latest aws-account-id.dkr.ecr.ap-northeast-2.amazonaws.com/joinc/hello-world:latest docker push aws-account-id.dkr.ecr.ap-northeast-2.amazonaws.com/joinc/hello-world:0.1 The push refers to repository [aws-account-id.dkr.ecr.ap-northeast-2.amazonaws.com/joinc/hello-world] 9f2145cdc3bb: Pushed ``` 이제 아래와 같이, Push한 Image를 확인 할 수 있다.  잘 작동하는지 로컬 PC에서 테스트해보자. ``` $ docker run -d --name joinc-hello -p 8080:8080 aws-account-id.dkr.ecr.ap-northeast-2.amazonaws.com/joinc/hello-world 64601f930626a3968deb199272013a193b820044334c07f0532dea9d1afdd0db ``` 
Recent Posts
MLOps with Joinc - Kubeflow 설치
Vertex Gemini 기반 AI 에이전트 개발 05. 첫 번째 LLM 애플리케이션 개발
LLama-3.2-Vision 테스트
Vertex Gemini 기반 AI 에이전트 개발 04. 프롬프트 엔지니어링
Vertex Gemini 기반 AI 에이전트 개발 03. Vertex AI Gemini 둘러보기
Vertex Gemini 기반 AI 에이전트 개발 02. 생성 AI에 대해서
Vertex Gemini 기반 AI 에이전트 개발 01. 소개
Vertex Gemini 기반 AI 에이전트 개발-소개
생성 AI 모델 Flux.1 설치 및 사용
GPT를 이용한 Reranker 테스트
Archive Posts
Tags
aws
docker
ecs
Copyrights © -
Joinc
, All Rights Reserved.
Inherited From -
Yundream
Rebranded By -
Joonphil
Recent Posts
Archive Posts
Tags