๐Ÿ‘จโ€๐Ÿ’ป Jetbrains Dev Container: ํ™˜๊ฒฝ ์ผ๊ด€์„ฑ์œผ๋กœ 'It works on my machine'์„ ํ•ด๊ฒฐํ•˜์ž

 

Dev Container overview

Dev Container๋ž€ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ํšจ์œจ์ ์œผ๋กœ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ์ˆ ์ž…๋‹ˆ๋‹ค.

์ œ๊ฐ€ ์ฆ๊ฒจ ์‚ฌ์šฉํ•˜๋Š” Jetbrains์˜ IDE์ธ IntelliJ IDEA, Pycharm, RubyMind์—์„œ๋Š” Dev Container ๊ธฐ์ˆ ์„ ํ™œ์šฉํ•˜์—ฌ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑ, ์ˆ˜์ • ๋ฐ ๋นŒ๋“œํ•˜๊ณ  ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

Docker Compose๋ฅผ ์ด์šฉํ•˜์—ฌ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋กœ ๊ตฌ์„ฑ๋œ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ์‰ฝ๊ฒŒ ๊ตฌ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Advantages

Dev Container๋ฅผ ์ด์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์ ์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

  • ํ™˜๊ฒฝ ์ผ๊ด€์„ฑ(Environment consistency)
    • ์ƒˆ๋กœ์šด ํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๊ฑฐ๋‚˜ ๊ธฐ์กด ํ”„๋กœ์ ํŠธ๋ฅผ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ํ•  ๋•Œ, Dev Container๋Š” ํ”„๋กœ์ ํŠธ ์ฐธ์—ฌ์ž์—๊ฒŒ ๋™์ผํ•œ ์„ค์ •์„ ํ†ตํ•ด์„œ ๋™์ผํ•œ ํ™˜๊ฒฝ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ด๋กœ์จ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๊ฐœ์ธ ์žฅ๋น„์—์„œ ๊ฐ๊ฐ ๋‹ค๋ฅด๊ฒŒ ๋™์ž‘(It works on my machine)ํ•˜๋Š” ๋ฌธ์ œ๋ฅผ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋น ๋ฅธ ํ™˜๊ฒฝ ๊ตฌ์„ฑ
    • ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•˜๋Š” ์ž‘์—…์€ ์ข…์ข… ๋งŽ์€ ์‹œ๊ฐ„์ด ์†Œ์š”๋ฉ๋‹ˆ๋‹ค. Dev Container๋Š” ๋ช‡ ๊ฐ€์ง€ ์„ค์ • ํŒŒ์ผ๊ณผ ๋ช…๋ น์–ด๋งŒ์„ ์ด์šฉํ•˜์—ฌ ๋น ๋ฅด๊ฒŒ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ณด์•ˆ ๋ฐ ๋…๋ฆฝ์„ฑ
    • Dev Container๋Š” ๋กœ์ปฌ ์šด์˜์ฒด์ œ์™€ ์™„์ „ํžˆ ๋…๋ฆฝ๋˜์–ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ๊ฐœ๋ฐœ ๋„๊ตฌ์™€์˜ ํ˜ธํ™˜์„ฑ ๋ฌธ์ œ ์—†์ด ์ƒˆ๋กœ์šด ๊ธฐ์ˆ ์„ ์‹œ๋„ํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์‰ฌ์šด ์œ ์ง€๋ณด์ˆ˜์™€ ์—…๋ฐ์ดํŠธ
    • ๊ธฐ์กด ๋ฐฉ์‹๋ณด๋‹ค ๊ฐœ๋ฐœ ๋„๊ตฌ์™€ ์˜์กด์„ฑ์„ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๊ณผ์ •์ด ๋‹จ์ˆœํ•˜๊ณ  ํŽธ๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
  • ์›๊ฒฉ ๊ฐœ๋ฐœ
    • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋Š” ๋กœ์ปฌ ๋จธ์‹ ๊ณผ ๋–จ์–ด์ง„ ์›๊ฒฉ ๋จธ์‹ ์—์„œ๋„ ์‹คํ–‰๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Dev Container๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›๊ฒฉ ๋จธ์‹ ์—์„œ ์‹คํ–‰๋˜๋Š” ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์œผ๋กœ ์—ฐ๊ฒฐํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Prerequisites

1. Jetbrains IDE ์„ค์น˜

์•„๋ž˜ ์ฃผ์†Œ์— ๋ฐฉ๋ฌธํ•˜์—ฌ ํ•„์š”ํ•œ IDE๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

Community Edition์—์„œ๋Š” Dev Containers ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

www.jetbrains.com

2. Docker ์„ค์น˜

์ €๋Š” MacOS๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, Docker Desktop์„ ์„ค์น˜ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

Colima๋Š” ์ง€์›๋˜์ง€ ์•Š๋Š” ๊ฒƒ์œผ๋กœ ์•Œ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์•„๋ž˜ ์ฃผ์†Œ์— ๋ฐฉ๋ฌธํ•˜์—ฌ Docker Desktop์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

www.docker.com

Start Dev Container from IDE welcome screen

์—ฌ๊ธฐ์„œ๋Š” IntelliJ Ultimate 2024.3 ๋ฒ„์ „์„ ๊ธฐ์ค€์œผ๋กœ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

IntelliJ๋ฅผ ์ตœ์ดˆ๋กœ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ๋‚˜ํƒ€๋‚˜๋Š” Welcome to IntelliJ IDEA์—์„œ ์ดˆ๊ธฐ ๊ตฌ์„ฑ์„ ์‹œ์ž‘ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ทธ ์™ธ์˜ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ๋Š” ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

1. Dev Container ์„ค์ • ํŒŒ์ผ ์ž‘์„ฑ ๋ฐ ์‹คํ–‰

  1. ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•  ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด๋ถ€์— .devcontainer ํด๋”๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํด๋” ๋‚ด๋ถ€์— devcontainer.json ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ํ•ด๋‹น ํŒŒ์ผ์„ ํ†ตํ•ด์„œ ์‹ค์ œ Dev Container๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
    {
       "name"   : "Test Dev Container"
     , "service": "spring-project"
     , "build": { "dockerfile": "Dockerfile" }
     , "remoteUser": "root"
     , "postCreateCommand": "java --version"
     , "customizations"   : { "jetbrains": {"backend": "IntelliJ"} }
    } 
    
  2. Welcome Screen์—์„œ Remote Development ๋…ธ๋“œ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.

  3. ์„ ํƒ ๊ฐ€๋Šฅํ•œ ์˜ต์…˜ ์ค‘์—์„œ Dev Containers๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค. IntelliJ IDEA Welcome Screen

  4. ์ƒˆ๋กญ๊ฒŒ ์—ด๋ฆฐ ํŽ˜์ด์ง€๊ฐ€ ์—ด๋ฆฝ๋‹ˆ๋‹ค. ๋กœ์ปฌ์—์„œ ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š” ๋„์ปค ์—”์ง„๊ณผ ์ž๋™์œผ๋กœ ์ปค๋„ฅ์…˜์„ ๋งบ์Šต๋‹ˆ๋‹ค.
    ๋งŒ์•ฝ ์ปค๋„ฅ์…˜์ด ๋งบ์–ด์ง€์ง€ ์•Š์•˜๋‹ค๋ฉด, ๋„์ปค ์—”์ง„์ด ์ œ๋Œ€๋กœ ์‹คํ–‰๋˜๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”.

  5. Dev Container์—์„œ ์‚ฌ์šฉํ•  ๋ฐฑ์—”๋“œ IDE๋ฅผ ์„ ํƒํ•˜์„ธ์š”.
    ์—ฌ๊ธฐ์—์„œ๋Š” IntelliJ IDEA๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  6. ์ƒ๋‹จ์— VSC๋‚˜ ๋กœ์ปฌ์—์„œ ์‚ฌ์šฉํ•  ํ”„๋กœ์ ํŠธ๋ฅผ ์„ ํƒํ•˜๋Š” ํƒญ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ฌธ์„œ์—์„œ๋Š” ๋กœ์ปฌ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

  7. Path to devcontainer.json ํ•„๋“œ์— 1๋ฒˆ์—์„œ ์ž‘์„ฑํ•œ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  Build Container and Continue ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
    IntelliJ IDEA Welcome Screen



References
jetbrains.com
containers.dev