> For the complete documentation index, see [llms.txt](https://organization-bht.gitbook.io/it/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://organization-bht.gitbook.io/it/ci-cd/2/1./undefined-1.md). Agents can also search and read this documentation through its [MCP server](https://organization-bht.gitbook.io/it/~gitbook/mcp).

# 도커 실습 순서

* 도커 실습 테스트 필요

## 1) Docker Image 만들기

```bash
# 1-1) Nginx 경량 이미지 내려받기
docker pull nginx:alpine

# 1-2) 내 계정 네임스페이스로 태그(예: hub ID가 myid라면)
docker tag nginx:alpine myid/hello-nginx:0.1

# 1-3) 이미지 확인
docker image ls
```

* 공식 이미지에 내 태그를 붙이기.

## 2) Docker Container 실행하기

```bash
# -d: 백그라운드, -p: 포트 포워딩(호스트 8080 → 컨테이너 80)
docker run -d --name hello-nginx -p 8080:80 myid/hello-nginx:0.1

# 브라우저에서 http://localhost:8080 확인

docker logs hello-nginx
docker stop hello-nginx
docker rm hello-nginx
```

## 3) Docker File만들기

```
docker-workspace/
├─ site/
│  └─ index.html
└─ Dockerfile
```

```html
<!doctype html>
<html>
  <head><meta charset="utf-8"><title>Hello Docker</title></head>
  <body>
    <h1>🚀 Hello from Docker + Nginx!</h1>
  </body>
</html>
```

```docker
# 베이스로 공식 Nginx 사용(가볍고 빠름)
FROM nginx:alpine
# 내 정적 파일을 Nginx 기본 루트로 복사
COPY ./site /usr/share/nginx/html
```

```bash
# 이미지 빌드 (-t: 이름:태그)
docker build -t myid/hello-nginx:1.0 .

# 컨테이너 실행 (--rm: 종료 시 자동 삭제)
docker run --rm -p 8081:80 myid/hello-nginx:1.0

# 브라우저에서 http://localhost:8081 로 커스텀 페이지 확인
```

## 4) Docker hub에 배포하기

```bash
# 4-1) 로그인
docker login

# 4-2) 푸시
docker push myid/hello-nginx:1.0

docker pull myid/hello-nginx:1.0
docker run -d -p 8080:80 myid/hello-nginx:1.0
```

```bash
# 실행중 컨테이너/이미지 목록
docker ps
docker images

# 컨테이너/이미지 정리
docker stop hello-nginx && docker rm hello-nginx
docker rmi myid/hello-nginx:1.0
```
