Skip to main content

One post tagged with "Troubleshooting"

View All Tags

๐Ÿ‹ Python ํ”„๋กœ์ ํŠธ๋ฅผ ์œ„ํ•œ Docker ๋ฒ ์ด์Šค ์ด๋ฏธ์ง€ ์„ ํƒ ์‹œ Alpine Linux๋ฅผ ํ”ผํ•ด์•ผ ํ•˜๋Š” ์ด์œ 

Chanho Lee
๋‹ค์–‘ํ•œ ๋ถ„์•ผ๋ฅผ ๊ณต๋ถ€ํ•˜๊ณ  ์žˆ๋Š” ํ•™์ƒ

Introductionโ€‹

Django๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ธ”๋กœ๊ทธ๋ฅผ ๋งŒ๋“ค์–ด๋ณด๋Š” ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋‹ค๊ฐ€ docker๋กœ ํ™˜๊ฒฝ์„ ์˜ฎ๊ธฐ๋Š” ๋„์ค‘ ์—ฌ๋Ÿฌ ์—๋Ÿฌ๋“ค์„ ๋งŒ๋‚ฌ๋‹ค. ์ด ๊ธ€์€ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ฉด์„œ ์–ป์€ ์ง€์‹์„ ๊ณต์œ ํ•˜๊ณ ์ž ์ž‘์„ฑํ•œ ๊ธ€์ด๋‹ค.

์ฒซ ๋ฒˆ์งธ ๋ฌธ์ œโ€‹

Alpine Linux์™€ cryptography์˜ ํ˜ธํ™˜์„ฑ ๋ฌธ์ œโ€‹

Dockerfile, docker-compose.yml ํŒŒ์ผ์„ ์ž‘์„ฑ ํ›„ ๋งˆ์ง€๋ง‰์œผ๋กœ ๋นŒ๋“œ๋ฅผ ํ•˜๋˜ ์ค‘ ์•„๋ž˜์˜ ์—๋Ÿฌ๋ฅผ ๋งŒ๋‚ฌ๋‹ค.

ERROR: No matching distribution found for cryptography==3.4.7

ํ˜„์žฌ Dockerfile์—์„œ ์‚ฌ์šฉํ•˜๋Š” image ๋ฒ„์ „๊ณผ requirements.txt์— ์ ํžŒ cryptography ๋ฒ„์ „์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. ์ด๋ ‡๊ฒŒ ์„ค์ •ํ•ด๋‘๊ณ  docker-compose๋กœ ๋นŒ๋“œ๋ฅผ ํ•˜๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๋‹ค.

FROM python:3.8-alpine
cryptography==3.4.7

ํ•ด๊ฒฐโ€‹

alpine linux์™€ python์—์„œ ์•”ํ˜ธํ™” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ๊ตฌํ˜„๋œ ํŒจํ‚ค์ง€์ธ cryptography์˜ ํ˜ธํ™˜์„ฑ ๋ฌธ์ œ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๊ณ , cryptography์˜ ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ•ด๊ฒฐ์ฑ…์„ ์ฐพ์•„๋ณด์•˜๋‹ค.

crypto-doc

๋Œ€๋žต ์š”์•ฝํ•˜๋ฉด cryptography ํŒจํ‚ค์ง€๋Š” Rust๋ฅผ ๋นŒ๋“œํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. ์ฆ‰, Rust์˜ ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž์ด์ž ๋นŒ๋“œ ๋„๊ตฌ์ธ cargo๋ฅผ ๊ฐ™์ด ์„ค์น˜ํ•ด์•ผ์ง€ ๋Œ์•„๊ฐ„๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

$ sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo

์œ„์˜ ์ฝ”๋“œ๋ฅผ Dockerfile์— ์ถ”๊ฐ€ํ•˜๋ฉด์„œ ์ฒซ ๋ฒˆ์งธ ๋ฌธ์ œ๋Š” ์ž˜ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

๋‘ ๋ฒˆ์งธ ๋ฌธ์ œโ€‹

๋นŒ๋“œ๊ฐ€ ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋‹ค๊ฐ€ ์•ˆ ๋˜๋Š” ๋ฌธ์ œโ€‹

์œ„์˜ ๋ช…๋ น์–ด๋ฅผ Dockerfile์— ์ถ”๊ฐ€ํ•˜๊ณ  ๋‹ค์‹œ build ํ•˜๋ฉด ๋‹น์—ฐํžˆ ์ž˜ ์ž‘๋™๋  ๊ฑฐ๋ผ ์ƒ๊ฐํ–ˆ์œผ๋‚˜ ์•„๋ž˜์™€ ๊ฐ™์ด ๋‹ค์‹œ ํ•œ ๋ฒˆ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค. ์ด๋ฏธ์ง€๋ฅผ ๋ณด๋ฉด ์•Œ ์ˆ˜ ์žˆ๋“ฏ์ด still running์ด ์ง€์†๋˜๋Š” ์ƒํ™ฉ์ด๋‹ค. ๋Œ€๋žต 10๋ถ„ ์ •๋„ ๊ทธ๋Œ€๋กœ ๋†”๋’€๋Š”๋ฐ๋„ ๋นŒ๋“œ๊ฐ€ ์•ˆ ๋˜๊ณ  ๊ณ„์† ์ง„ํ–‰ํ•˜๋‹ค๊ฐ€ ์ข…๋ฃŒ๊ฐ€ ๋œ๋‹ค.

๋” ์ƒ์„ธํ•œ details

ํ•ด๊ฒฐโ€‹

๊ณ„์† ๊ตฌ๊ธ€๋ง์„ ํ•˜๋ฉด์„œ ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค ํ–ˆ์œผ๋ฉฐ, cryptography ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€์˜ ๋ฌธ์ œ์ผ ์ˆ˜๋„ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์—ฌ ๊ณต์‹ ๋ฌธ์„œ๋„ ๋‹ค์‹œ ๋‹ค ์ฝ์–ด๋ณด๊ณ , ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ GitHub ์ด์Šˆ๋„ ์ฐพ์•„๋ณด์•˜๋‹ค.

๋” ์ƒ์„ธํ•œ details

๋Œ€๋žต์ ์œผ๋กœ ๋น„์Šทํ•œ ์ด์Šˆ๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์—ˆ๋‹ค. ์œ„์˜ ์ด๋ฏธ์ง€๋Š” cryptography GitHub ์ €์žฅ์†Œ์—์„œ ๊ฐ€์ ธ์˜จ ํ•œ ์ด์Šˆ ์ด๋ฏธ์ง€๋‹ค. ํ˜„์žฌ์˜ ์ƒํ™ฉ๊ณผ ๋น„์Šทํ•˜์—ฌ ๋‹ต๋ณ€์„ ์ฐธ๊ณ ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

๋Œ€๋žต ์š”์•ฝํ•˜์ž๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

  1. Alpine Linux์—์„œ Python ํŒจํ‚ค์ง€๋ฅผ ๋นŒ๋“œํ•˜๋Š” ์ž‘์—…์ด ๋Š๋ฆฌ๋ฉฐ, ํŠนํžˆ CI/CD ํ™˜๊ฒฝ์—์„œ ๋งค๋ฒˆ ๋นŒ๋“œํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ๋น„ํšจ์œจ์ ์ด๋‹ค.
  2. Python์˜ pip ๋ฐ ํœ  ํŒจํ‚ค์ง•๊ณผ ๊ด€๋ จํ•˜์—ฌ Alpine๊ณผ ํ˜ธํ™˜ ๊ฐ€๋Šฅํ•œ ํœ ์„ ์—…๋กœ๋“œํ•˜๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜์ง€๋งŒ, ์ด๋Š” pip/wheel/packaging ๋ฐ ๊ด€๋ จ PEP ๋…ผ์˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
  3. ์ตœ์‹  Alpine ํ™˜๊ฒฝ์—์„œ Python ํŒจํ‚ค์ง€๋ฅผ ์ œ๋Œ€๋กœ ์„ค์น˜ํ•˜๋ ค๋ฉด ์ตœ์‹  Rust ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
  4. Alpine์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์ด์™€ ๊ฐ™์€ ๋ฌธ์ œ๋Š” ๋ฌธ์„œํ™”๋˜์–ด ์žˆ๊ณ , ํ˜„์žฌ๋กœ์„œ๋Š” ๊ฐœ์„  ์‚ฌํ•ญ์ด ์—†์œผ๋ฏ€๋กœ ์ถ”๊ฐ€์ ์ธ ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค๋ฉด ์ƒˆ๋กœ์šด ์ด์Šˆ๋ฅผ ์—ด๊ฑฐ๋‚˜ PR(Pull Request)์„ ์ œ์ถœํ•ด์•ผ ํ•œ๋‹ค.

์ด ๋‹ต๋ณ€์—์„œ์˜ ํ•ต์‹ฌ์€ ๊ฒฐ๊ตญ 1๋ฒˆ๊ณผ 2๋ฒˆ์ด์—ˆ๋‹ค. ์ฆ‰, Alpine ๋ฆฌ๋ˆ…์Šค๊ฐ€ ๋ฌธ์ œ์˜€๊ณ , ์•„๋ž˜์™€ ๊ฐ™์ด ์ด๋ฏธ์ง€๋งŒ ๋ฐ”๊ฟˆ์œผ๋กœ์„œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

FROM python:3.8-slim-buster

๊ทผ๋ฐ ๋ฌธ์ œ๋งŒ ํ•ด๊ฒฐํ•˜๋ฉด ๋์ผ๊นŒ? ๊ทธ๊ฑด ์•„๋‹ˆ๋‹ค. ์ด์œ ๋ฅผ ์•Œ์•„๋ณด์ž.

Alpine Linux๊ฐ€ ํŒŒ์ด์ฌ ํ™˜๊ฒฝ์—์„œ ์ ์ ˆํ•˜์ง€ ์•Š์€ ์ด์œ โ€‹

๋‚ด๊ฐ€ alpine linux๋ฅผ ์‚ฌ์šฉํ•œ ์ด์œ ๋Š” Ubuntu linux์™€ ๋น„๊ตํ–ˆ์„ ๋•Œ ์šฉ๋Ÿ‰๋„ ์ž‘๊ณ  ๋นŒ๋“œํ•  ๋•Œ ๋” ๋น ๋ฅด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ฆ‰, ๊ฒฝ๋Ÿ‰ํ™”๊ฐ€ ์ž˜ ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ด ์ด๋ฏธ์ง€๋Š” python ํ™˜๊ฒฝ์—์„œ๋Š” ์ ์ ˆํ•˜์ง€ ์•Š๋‹ค.

๊ทธ ์ด์œ ๋Š” ์‚ฌ์šฉํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ์ฐจ์ด์—์„œ ์‹œ์ž‘๋œ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๋ฆฌ๋ˆ…์Šค ๋ฐฐํฌํŒ์€ ํŒŒ์ด์ฌ์„ ํฌํ•จํ•œ ๋ชจ๋“  C์–ธ์–ด ํ”„๋กœ๊ทธ๋žจ์— ํ•„์š”ํ•œ C์–ธ์–ด ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ GNU ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(glibc)๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ Alpine Linux๋Š” ์ข€ ๋” ๊ฒฝ๋Ÿ‰ํ™”ํ•˜๊ธฐ ์œ„ํ•˜์—ฌ GNU ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ musl ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ์ด musl ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” GNU ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ์ปดํŒŒ์ผ ๋œ Wheel ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— .whl ํ™•์žฅ์ž๋ฅผ ๊ฐ–๋Š” ํŒจํ‚ค์ง€๋ฅผ ๋‹ค์šด ๋ฐ›๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ .tar.gz ํ™•์žฅ์ž ํŒŒ์ผ์„ ๋‹ค์šด ๋ฐ›๊ฒŒ ๋œ๋‹ค. ์ฆ‰, alpine linux๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ํŒŒ์ด์ฌ ํŒจํ‚ค์ง€์˜ C ์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผ ํ•ด์•ผ ํ•˜๋ฏ€๋กœ ๋นŒ๋“œ ์‹œ๊ฐ„๋„ ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋ฉฐ ์šฉ๋Ÿ‰๋„ ์ปค์ง„๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

์ตœ๊ทผ ๋Œ€๋ถ€๋ถ„์˜ ํŒŒ์ด์ฌ ํŒจํ‚ค์ง€์—๋Š” PyPI์˜ Wheel ๋ฐ”์ด๋„ˆ๋ฆฌ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์–ด ์„ค์น˜ ์‹œ๊ฐ„์ด ๋น ๋ฅด๋‹ค. Wheel์€ ์‚ฌ์‹ค .whl ํ™•์žฅ์ž์™€ ํŠน๋ณ„ํ•œ ํ˜•์‹์˜ ํŒŒ์ผ ์ด๋ฆ„์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ZIP ํ˜•์‹์„ ์•„์นด์ด๋ธŒํ•œ ๊ฒƒ์ด๋‹ค. ์‰ฝ๊ฒŒ ๋งํ•˜๋ฉด ํ™•์žฅ์ž๋งŒ ๋ฐ”๊พผ ๊ฒƒ์ด๋‹ค.

  1. ๋นŒ๋“œ๊ฐ€ ๋Š๋ฆฌ๋‹ค.
  2. ์ด๋ฏธ์ง€ ์šฉ๋Ÿ‰์ด ์ปค์ง„๋‹ค.
  3. ์‹œ๊ฐ„์ด ๋งŽ์ด ๋‚ญ๋น„๋œ๋‹ค.(๋นŒ๋“œํ•˜๋Š” ๊ณผ์ •)
  4. ๋Ÿฐํƒ€์ž„ ๋ฒ„๊ทธ๋“ค์„ ๋งŒ๋‚  ์ˆ˜ ์žˆ๋‹ค.

์œ„์˜ ์ด์œ ๋“ค๋กœ ์ธํ•ด, Python ํ™˜๊ฒฝ์—์„œ๋Š” Alpine Linux๋ณด๋‹ค๋Š” Debian ๊ธฐ๋ฐ˜์˜ slim ์ด๋ฏธ์ง€๋‚˜ Ubuntu ๊ธฐ๋ฐ˜ ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋” ์ ํ•ฉํ•˜๋‹ค.

๐ŸŒReferencesโ€‹