Amazon Lightsail 기반 컨테이너 웹 앱 배포

시작 안내서

모듈 3: 컨테이너 배포

이 모듈에서는 컨테이너를 클라우드로 배포합니다

소개

이제 Amazon Lightsail Container Service가 준비되었으며 다음 단계는 컨테이너 배포입니다.

Amazon Lightsail는 Docker Hub, Amazon ECR Public Gallery 또는 로컬 시스템과 같은 퍼블릭 컨테이너 이미지 리포지토리에서 컨테이너를 배포할 수 있습니다.

이 가이드에서는 로컬 시스템에서 직접 배포합니다.

학습 내용

  • 로컬 컨테이너 이미지를 Amazon Lightsail로 푸시하는 방법
  • Container Service에 컨테이너 이미지의 버전을 배포하는 방법

 소요 시간

10분

 모듈 선행 조건

  • 관리자 수준의 액세스 권한이 있는 AWS 계정**
  • 권장 브라우저: 최신 버전의 Chrome 또는 Firefox

[**]생성된 지 24시간이 지나지 않은 계정은 이 자습서를 완료하는 데 필요한 서비스에 액세스할 권한이 아직 없을 수 있습니다.

구현

로컬 컨테이너 이미지 푸시

컨테이너 배포의 첫 번째 단계는 컨테이너 이미지를 Amazon Lightsail로 푸시하는 것입니다

컨테이너를 생성한 디렉터리에서 터미널을 열고 다음 명령을 입력합니다. Lightsail Container Service를 생성한 리전과 동일한 리전을 사용하는지 확인하세요.

aws lightsail push-container-image    \
    --region eu-west-3                \
    --service-name signup-application \
    --label latest                    \
    --image demo-flask-signup:latest

# the command outputs the following lines
f017a6ddb209: Pushed 
b94dee417b5e: Pushed 
37d77b23a488: Pushed 
8e77a3b871e7: Pushed 
4bc5d67b6427: Pushed 
ce8ffb5c560e: Pushed 
4226d5d0360f: Pushed 
9d1af766c818: Pushed 
d97733c0a3b6: Pushed 
c553c6ba5f13: Pushed 
48b4a40de359: Pushed 
ace9ed9bcfaf: Pushed 
764055ebc9a7: Pushed 
Digest: sha256:128f84907d30a1fb47c1888720485fa8050cc99bc1034e0cfd1f46d3b6e57e19
Image "demo-flask-signup:latest" registered.
Refer to this image as ":signup-application.latest.1" in deployments.    

이 명령은 Docker 푸시를 호출하여 이미지를 Amazon Lightsail로 업로드합니다. 완료하는 데 몇 분 정도 걸릴 수 있으며 네트워크 대역폭에 따라 다릅니다.

출력의 마지막 줄은 컨테이너 내부의 이름을 제공하는 것입니다. 이 경우, :signup-application.latest.1입니다. 컨테이너를 컨테이너 서비스에 배치하려면 이 이름이 필요하므로 메모해 두시기 바랍니다. 이후 단계에서 컨테이너 이름에 액세스하려는 경우, 다음 명령을 입력합니다.

aws lightsail get-container-images    \
    --region eu-west-3                \
    --service-name signup-application

# the command outputs the following lines
{
    "containerImages": [
        {
            "image": ":signup-application.latest.1",
            "digest": "sha256:128f84907d30a1fb47c1888720485fa8050cc99bc1034e0cfd1f46d3b6e57e19",
            "createdAt": "2021-07-17T15:11:49+02:00"
        }
    ]
}  

로컬 컨테이너 이미지를 LightSail로 푸시

이제 컨테이너 이미지가 Amazon Lightsail에 저장되었으며 해당 이미지를 컨테이너 서비스에 배포할 수 있습니다.

배포를 생성하려면 Lightsail에는다음 정보가 필요합니다.

  • 배포할 컨테이너 이미지의 이름(:signup-application.latest.1, 이전 명령에 의해 반환된 대로)
  • 컨테이너에 의해 노출된 네트워크 포트(Docker 파일 구성에 설명된 대로)
  • (선택 사항) 공개적으로 액세스 가능한 네트워크 엔드포인트의 세부 정보: TCP 포트 번호 및 프로토콜, IP가 자동으로 할당됩니다.

이러한 모든 정보는 배포 전에 생성해야 하는 JSON 파일에 저장됩니다.

lc.json이라는 이름의 JSON 파일을 생성합니다. 다운로드된 코드에서 작업하는 경우, 컨테이너와 동일한 디렉터리에 있는 기존 lc.json 파일을 수정합니다. 다음 json을 파일 내에 복사합니다.

{
    "serviceName": "signup-application",
    "containers": {
        "signup-app-container": {
            "image": ":signup-application.latest.1",
            "ports": {
                "80": "HTTP"
            }
        }
    },
    "publicEndpoint": {
        "containerName": "signup-app-container",
        "containerPort": 80
    }
}

그런 다음, 다음 명령을 입력하여 컨테이너를 배포합니다.

aws lightsail create-container-service-deployment \
    --region eu-west-3                            \
    --cli-input-json file://lc.json

# the command outputs the following 

{
    "containerService": {
        "containerServiceName": "signup-application",
        "arn": "arn:aws:lightsail:eu-west-3:012345678901:ContainerService/528a0bcf-fd14-42d4-a09a-943a241adc51",
        "createdAt": "2021-07-17T13:38:40+02:00",
        "location": {
            "availabilityZone": "all",
            "regionName": "eu-west-3"
        },
        "resourceType": "ContainerService",
        "tags": [],
        "power": "nano",
        "powerId": "nano-1",
        "state": "DEPLOYING",
        "scale": 2,
        "nextDeployment": {
            "version": 1,
            "state": "ACTIVATING",
            "containers": {
                "signup-app-container": {
                    "image": ":signup-application.latest.1",
                    "command": [],
                    "environment": {},
                    "ports": {
                        "80": "HTTP"
                    }
                }
            },
            "publicEndpoint": {
                "containerName": "signup-app-container",
                "containerPort": 80,
                "healthCheck": {
                    "healthyThreshold": 2,
                    "unhealthyThreshold": 2,
                    "timeoutSeconds": 2,
                    "intervalSeconds": 5,
                    "path": "/",
                    "successCodes": "200-499"
                }
            },
            "createdAt": "2021-07-17T15:31:01+02:00"
        },
        "isDisabled": false,
        "principalArn": "arn:aws:iam::577312533299:role/amazon/lightsail/eu-west-3/containers/signup-application/1jetjd21p8qshe57seuh71tnrnn29ps77lnno20sbgl2ghbuc0r0",
        "privateDomainName": "signup-application.service.local",
        "url": "https://signup-application.me04fvc6dbk4e.eu-west-3.cs.amazonlightsail.com/"
    }
}

"상태"는 "PENDING" 상태입니다.. 잠시 후 상태가 ACTIVE로 변경됩니다. 배포를 완료하는 데는 몇 분 정도 걸립니다. 다음 명령을 사용하여 배포 상태를 확인할 수 있습니다.

# while deploying
aws lightsail get-container-services      \
    --region eu-west-3                    \
    --query "containerServices[].nextDeployment.state"

# once deployed
aws lightsail get-container-services      \
    --region eu-west-3                    \
    --query "containerServices[].currentDeployment.state" 

배포 테스트

배포를 테스트하려면 먼저 생성된 URL Lightsail을 검색합니다. 터미널을 열고 다음 명령을 입력합니다.

aws lightsail get-container-services        \
    --region eu-west-3                      \
    --query "containerServices[].url" 

# the command outputs something like the below 
[
    "https://signup-application.me04fvc6dbk4e.eu-west-3.cs.amazonlightsail.com/"
]

즐겨 찾는 브라우저를 열고 배포 URL을 가리킵니다.

대신 명령줄에서 엔드포인트를 테스트하기 위해 cURL를 사용할 수 있습니다.

curl -I https://signup-application.me04fvc6dbk4e.eu-west-3.cs.amazonlightsail.com/

HTTP/2 200 
date: Sat, 17 Jul 2021 13:38:04 GMT
content-type: text/html; charset=utf-8
content-length: 4579
server: nginx/1.21.1

축하합니다. 이제 컨테이너가 Amazon Lightsail에 배포되었습니다.

결론

이 가이드에서는 Amazon Lightsail에 컨테이너를 배포하는 방법을 알아봤습니다. 다음 모듈에서는 컨테이너를 업데이트하는 방법을 알아봅니다.

다음: 컨테이너 업데이트

내용이 마음에 드셨는지요.