๊ด€๋ฆฌ ๋ฉ”๋‰ด

ruriruriya

[Docker] ๋„์ปค ์„ค์น˜ ๋ฐฉ๋ฒ• ๋ฐ ํ™˜๊ฒฝ์„ค์ •ํ•˜๊ธฐ ๋ณธ๋ฌธ

๐ŸณDocker

[Docker] ๋„์ปค ์„ค์น˜ ๋ฐฉ๋ฒ• ๋ฐ ํ™˜๊ฒฝ์„ค์ •ํ•˜๊ธฐ

๋ฃจ๋ฆฌ์•ผใ…‘ 2024. 2. 27. 23:07
๋ฐ˜์‘ํ˜•

 

1. ์šฐ์„  ๋„์ปค ํ™ˆํŽ˜์ด์ง€์—์„œ ๋„์ปค๋ฅผ ์„ค์น˜ ํ•œ๋‹ค.

https://www.docker.com/

 

Docker: Accelerated Container Application Development

Docker is a platform designed to help developers build, share, and run container applications. We handle the tedious setup, so you can focus on the code.

www.docker.com

ํšŒ์›๊ฐ€์ž…์„ ํ•˜๊ณ 

ํšŒ์›๊ฐ€์ž…์ด ๋๋‚˜๋ฉด Tell us about the wolrk you do์—์„œ๋Š” skip์„ ํด๋ฆญํ•œ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์„ค์น˜๋œ ๋„์ปค ๋ฐ์Šคํฌํ†ฑ์„ ์—ด์–ด ๋กœ๊ทธ์ธ ํ•˜๋ฉด ๋œ๋‹ค.

 

2. ๋„์ปค ์‹คํ–‰์„ ์œ„ํ•œ ์„ค์ •

2.1. serverless.yml ํŒŒ์ผ ์ˆ˜์ •

provider:
	name: aws
	runtime: python3.10
	region: ap-northeast-2
	ecr:
		images:
			appimage:
				path: ./

functions:
	app:
		image:
			name: appimage
		timeout: 50
		events:
			- httpApi: '*'

 

2.2. requirements.txt ํŒŒ์ผ ์ˆ˜์ •(์•„๋ž˜ ๋‚ด์šฉ ์ถ”๊ฐ€)

serverless-wsgi

flask-restful
mysql-connector-python
psycopg-binary
passlib
flask-jwt-extended
email-validator

 

2.3. app.py import

import serverless_wsgi

.
.
.
def handler(event, context):
return serverless_wsgi.handle_request(app, event, context)

if **name** == '**main**' :

app.run()

 

2.4. Dockerfile ์ƒ์„ฑ

FROM public.ecr.aws/lambda/python:3.10
COPY . ${LAMBDA_TASK_ROOT}
COPY  requirements.txt .

RUN yum -y install gcc
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"

CMD ["app.handler"]

 

2.5. .dockerignore ํŒŒ์ผ ์ƒ์„ฑ

#.dockerignore
pycache/
.git/
.serverless/
.gitignore
.dockerignore
serverless.yml

 

๋ฐ˜์‘ํ˜•