개발 컨테이너 구성

EEEFFEE·2024년 1월 31일

docker 관리도구

목록 보기
1/2

24.01.31 최초 작성

1. Docker 설치

  • host환경에서 docker 설치

# 필요 패키지 설치
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

# docker gpg키 추가
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# docker apt 저장소 추가
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

sudo apt-get update

# docker 설치
sudo apt-get install docker-ce docker-ce-cli containerd.io

# docker 사용할 수 있는 사용자 그룹에 유저 추가
usermod -aG docker <유저 이름>

chmod 666 /var/run/docker.sock
service docker restart

2. Vscode 설정

  • 컨테이너에서 실행되는 vscode를 연결하기
  • Extension 설치
    • Docker
    • Dev Containers
    • Python

2.1 개발 컨테이너 추가

  • vscode에서 ctrl + shift + p를 통해 팔레트 open

  • add dev container 입력, 선택

  • python 3 입력, 3.10-bullseye 선택, .devcontainer 파일 생성됨

  • 팔레트에서 Dev Containers: Reopen in Container선택해 시작

2.2 컨테이너 검사

  • 터미널에서 구성한 환경 확인

2.3 컨테이너 설정

  • 컨테이너의 .devcontainer/devcontainer.json에서 설정 가능

{
	"name": "Python 3",
	
    //컨테이너 이미지 이름 설정
	"image": "mcr.microsoft.com/devcontainers/python:1-3.10-bullseye"

	// Features to add to the dev container. More info: https://containers.dev/features.
	// "features": {},

	// 포트포워딩 설정
	// "forwardPorts": [],

	// 컨테이너 생성 시 실행하려는 명령어 및 설치하려는 의존성 설정
	// "postCreateCommand": "pip3 install --user -r requirements.txt",

	// vscode 및 extension 설치 자동화
	// "customizations": {},

	// 개발환경에서 동작하는 사용자 설정
	// "remoteUser": "root"
}

3. ssh 환경 구성

3.1 server 환경

  1. host환경의 vscode에서 새 컨테이너 생성, ip주소 확인

  1. sudo apt install openssh-server로 ssh 설치

sudo apt update
sudo apt install openssh-server
sudo service ssh start

172.17.0.4

  1. guest환경에서 생성한 ssh-key를 다음과 같이 등록

echo <ssh-key> | tee -a ~/.ssh/authorized_keys

3.2 guest 환경

  1. 인증키 생성

ssh-keygen

cat ~/.ssh/id_rsa.pub

  1. ~/.ssh/config에 다음과 같이 입력

Host second
  HostName <server의 ip>
  StrictHostKeyChecking no
  IdentityFile ~/.ssh/id_rsa

  1. ssh second를 통해 server접속

0개의 댓글