[Hands-On] ECR, Docker image pull, Flask
많은 ERROR를 극복한 나의 Docker image pull 핸즈온 실습 복습이야기...
[1] 액세스 키 발급
맨 오른쪽 위 구석 계정 토글을 누르면
"보안 자격 증명"에 들어간 다음 액세스 키를 발급할 수 있음
액세스 키를 만들면
1. 액세스 키 아이디(Access key ID)
2. 비밀 액세스 키 암호(Secret access key)
를 얻을 수 있음
- Access Key 발급 후 credential 등록하기
aws configure --profile <profile_name> # profile 등록
# macos) 사용할 profile 전환 (window user는 해당사항 없음)
export AWS_PROFILE="<profile_name>"
aws sts get-caller-identity # 전환됐는지 확인




git clone <http://github.com ~~~ asc 링크>


flask run -port 5000 //1번 (flask 기본 포트가 5000)
//web에서 localhost:5000 접속 2번


Flask 실행하기 전에 환경변수 설정하기 - FLASK_APP, FLASK_ENV
flask run을 하려고 하면 "You did not provide the "FLASK_APP" environment variable"와 같은 오류가 생긴다. Flask 환경변수 오류이다. 필수 환경변수를 설정해보자. 1. 실행 파일 지정: FLASK_APP 2. 서버 환경 설정 (디
teki.tistory.com
이 블로그 글과 비슷한 내용의 이것저것 참고해서 해봤는데 안됐당


[4] Build Docker Image
[4-1] ECR login
>>aws ecr get-login-password --region <region> | docker login --username <user> --password-stdin <aws_account_ID>.dkr.ecr.<region>.amazonaws.com
내가 마주한 에러
1) An error occurred (UnrecognizedClientException) when calling the GetAuthorizationToken operation: The security token included in the request is invalid.
Error: Cannot perform an interactive login from a non TTY device
2) Error response from daemon: login attempt to https://<내 계정 ID>.dkr.ecr.ap-northeast-2.amazonaws.com/v2/ failed with status: 401 Unauthorized
aws: error: argument --region: expected one argument
별별 명령어를 다 실행해보다가...
하다가 레포지토리도 없어져서... 다시 만들고...(왜 없어진걸까...
처음부터 다시 해보려고 aws configure로 로그인을 다시 했는데 아마 그래서 인듯...?)
AWS CLI v2에서 아마존 ECR 로그인 방법 변경
지난 2월 AWS CLI v2가 릴리스 되고, 아마존 ECR 로그인 방법에도 변화가 생겼습니다. 기존에는 get-login 명령어를 사용해 ECR에 로그인을 했습니다만, v2에서는 이 명령어가 사라지고 그 자리를 get-login
www.44bits.io
이거는 버전 바뀌어서 잘못된 건가 하고 찾아봐서 했는데 안됐당
https://awstip.com/how-to-fix-cannot-perform-an-interactive-login-from-a-non-tty-device-error-full-guide-d6fbe10f259e
How to fix “cannot perform an interactive login from a non TTY device” error. Full guide.
Install docker
awstip.com
이걸로 해결했다!


[4-2] Docker Image Build
1번 >> docker build -t asc/docker-demo .
2번 >> docker images
1번을 무작정 하려니까 안돼서
>>cd 2023-docker-handson-smwu
이걸 만들어준다음에 했더니 잘됐다!
근데 repo 지정을 이번에 두 번째 하는거니까 바꿔줘야 ? 될 것 같아서 다시 저장했더니

[4-3] Run Docker Container
1) docker: Error response from daemon: Conflict. The container name "/asc-demo2-container" is already in use by container "d4d47f464043f8c2173e804acff43bd673beeaf319cf2369d34674bc6a747757". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
ERRO[0000] error waiting for container:
[Docker] docker 재실행시 address already in use 에러 해결
docker 가 실행 중인 ec2 인스턴스를 중지 후 재시작 했을 때 일부의 컨테이너가 중지되어진 상태 $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42758a99a6d2 gitlab/gitlab-ee:12.8.1-ee.0 "/assets/wrapper" 7
a-half-human-half-developer.tistory.com
도커 컴포즈 실행 디버깅
도커 컴포즈를 실행 시 다음과 같은 에러를 마주할 때가 있습니다. 이유는 "도커가 정상적으로 종료하지 않아서" 이다. 따라서 잡혀있는 포트의 pid를 찾은 후 종료하고 재실행하면 된다.
velog.io

이걸로 했는데도 해결이 안됐으나
https://aodtns.tistory.com/119
맥북에서 도커와 노드 사용 시 주의점
도커로 노드 js 이미지를 만들고 5000:8080으로 포트 매핑 후 run 해보니.. docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5000 -> 0.0.0.0:0: listen tcp 0.0.0.0:5000: bind: address already in use. ER
aodtns.tistory.com
오. 갓. 구세주여.
이걸로 깔끔하게 해결했다...
감격 그자체 ^_^
[5] Docker Tag command
도커 태그 명령을 실행하는 이유는
1- ECR에 푸시할 도커 이미지 이름은‘<aws_account_ID>.dkr.ecr.<region>.amazonaws.com/<image_name>’ 형식을 준수해야 하고,
2- 이미지 버전 관리를 위해 태그를 변경
라고 하는데 앞으로 여러 개를 한다면 이 태그변경을 준수해야겠지만
이번 실습에서는 latest로 진행했다
>> docker tag <레포이름>:latest <aws_account_ID>.dkr.ecr.<region>.amazonaws.com/<레포이름>:latest

>> docker push <aws_account_ID>.dkr.ecr.<region>.amazonaws.com/<레포이름>:latest
해주면 이렇게 push가 된다!

>> docker rmi <image_name>
(했는데도 안되면 그냥 수동으로 지웠다 ㅎ_ㅎ)
[7] Pull Docker Image
ECR의 docker image 가져오기
>> docker pull <aws_account_ID>.dkr.ecr.<region>.amazonaws.com/<레포이름>:latest



