Dev Containers을 이용한 container 생성
Dev Containers
Dockerfile만 정의하면 container 자동을 생성해주는 VSC의 Extension
Dockerfile을 이용한 Dev Containers 구동
Python 관련 container 생성 예시
-
Dockerfile 생성
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-devel RUN pip install -U openmim
-
Container Configuration File 생성
- Ctrl+Shift+P를 눌러 명령 팔레트 열어 Dev Containers: Add Dev Container Configuration Files… 실행
- Open a Remote Window 선택 후 Add Dev Container Configuration Files… 실행
Add configuration to workspace 선택
- Azure 가상 머신과 연결하여 진행했을 때는 이 과정 없었음
From ‘Dockerfile’ 선택
필요한 feature 선택하고 OK 선택
- 이 예시에서는 진행하지 않음
모든 과정을 거치면
.devcontainer
폴더에devcontainer.json
설정 파일 생성
생성된 설정 파일의 예시는 아래와 같음
// For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile { "name": "Existing Dockerfile", "build": { // Sets the run context to one level up instead of the .devcontainer folder. "context": "..", // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. "dockerfile": "../Dockerfile" } // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Uncomment the next line to run commands after the container is created. // "postCreateCommand": "cat /etc/os-release", // Configure tool-specific properties. // "customizations": {}, // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "devcontainer" }
-
devcontainer.json
설정 파일을 이용한 container 구동- Ctrl+Shift+P를 눌러 명령 팔레트 열어 Dev Containers: Rebuild & Reopen in Container 실행
- Open a Remote Window 선택 후 Add Dev Container Configuration Files… 실행
이 과정을 통해 container 구동
devcontainer.json
설정 파일 수정 되는 경우
Container를 생성하고 구동 중에 설정 파일을 수정하는 경우 rebuild 진행
-
devcontainer.json
설정 파일 수정// For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile { "name": "Existing Dockerfile", "build": { // Sets the run context to one level up instead of the .devcontainer folder. "context": "..", // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. "dockerfile": "../Dockerfile" }, "runArgs": ["--gpus=all"], "customizations": { "vscode": { "extensions": [ "ms-toolsai.jupyter", "github.copilot", "ms-python.python" ] } } // Features to add to the dev container. More info: https://containers.dev/features. // "features": {}, // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Uncomment the next line to run commands after the container is created. // "postCreateCommand": "cat /etc/os-release", // Configure tool-specific properties. // "customizations": {}, // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "devcontainer" }
- “runArgs”, “customizations” 추가
-
Rebuild 진행
- Ctrl+Shift+P를 눌러 명령 팔레트 열어 Dev Containers: Rebuild Container 실행
- Open a Remote Window 선택 후 Rebuild Container 실행