1. 개요

Improving job performance is very important.
2. Linux Operating System
2.1. LInux Distributions
2.2. File and Directory
2.3. Process
2.4. Shell Scripting
2.5. Commands & Options
2.6. Linux – Network Commands
2.7. Linux – Service and Daemons
2.8. Linux – misc.
- editor: vim, nano
3. Docker
3.1. 도커 소개
3.2. 실습환경 구축
- docker desktop 설치
3.3. 실습1: Hello world 실행
Bash
docker container run --rm hello-world
Bash3.4. 실습2: Interactive Shell 실행
Bash
docker container run --interactive --tty ubuntu
Bash3.5. 실습3: container run – env
3.6. docker-compose – down과 stop의 차이
3.7. 실습: Dockerfile로 디렉터리 볼륨 마운트하기
- volume의 개념: 컨테이너와 스토리지의 life cycle을 분리
- VOLUME 인스트럭션을 이용
- docker volume ls
- docker volume create volume_name
- docker container run -v volume_name:$target
3.8. 실습: bind mount 이용
Bash
docker container run --mount type=bind,source=$source,target=$target -d
Bash3.9. 실습: docker를 이용해 user권한의 python webserver를 구동하기
파일구조는 다음과 같다.
Bash
python-webserver/
├── Dockerfile
└── app/
└── server.py
Bash3.9.1. Dockerfile
Dockerfile
# Dockerfile
FROM python:3.10-slim
# 시스템 사용자 및 그룹 생성
RUN groupadd -r appuser && useradd -r -g appuser -d /app appuser
# 앱 디렉토리 생성 및 복사
WORKDIR /app
COPY app/ /app/
# 권한 부여
RUN chown -R appuser:appuser /app
# 비루트 사용자로 실행
USER appuser
# 서버 실행
CMD ["python", "server.py"]
Dockerfile
3.9.2. server.py
Python
# app/server.py
from http.server import HTTPServer, SimpleHTTPRequestHandler
PORT = 8000
print(f"Serving on port {PORT}")
httpd = HTTPServer(("0.0.0.0", PORT), SimpleHTTPRequestHandler)
httpd.serve_forever()
Python
3.9.3. 빌드 & 실행
Bash
# 빌드
docker build -t python-webserver .
# 실행 (포트 8000 바인딩)
docker run -p 8000:8000 python-webserver
Bash3.9.4. 개선 – detach
Bash
# 빌드
docker build -t python-webserver .
# 실행 (포트 8000 바인딩)
docker run --rm --detach -p 8000:8000 python-webserver
Bash
답글 남기기