> For the complete documentation index, see [llms.txt](https://haleyryu.gitbook.io/engineer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haleyryu.gitbook.io/engineer/python/dockerize/1.-build-a-python-docker-image.md).

# 1. Create Dockerfile

Dockerfile 생성하기

## Dockerfile 생성하기  🐳

**/Dockerfile**

```bash
FROM centos/python-36-centos7

# timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime

# path configs
ENV DEPLOY_HOME=/deploy
RUN mkdir -p $DEPLOY_HOME/
WORKDIR $DEPLOY_HOME

# python packages
ADD . $DEPLOY_HOME/
RUN pip install --upgrade -r requirements.txt

ENV PORT=8000 \
    NUM_WORKERS=4

ENTRYPOINT ["./docker-entry.sh"]
```

**./docker-entry.sh**

```bash
exec gunicorn server:app \
  --worker-class gunicorn.workers.ggevent.GeventWorker \
  --bind 0.0.0.0:$PORT "$@"
```

## 로컬에서 확인하기

#### Build Dockerfile

```bash
$ docker build -t {repository_name}
```

#### Run Docker Image

```bash
$ docker run -p 9000:8000 {repository_name}
```

#### Test API call

```
$ curl -X GET http://localhost:9000/
```

Example:

![](https://1715430459-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LcsheX9TIMwoBSNygvE%2F-Ld7v7qiFQkO-BwloVMl%2F-Ld88ubC2t1xrBb4VP1G%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202019-04-23%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%204.44.44.png?alt=media\&token=7389b964-2bbb-4381-ace6-a08ba718f0b5)

\-

### Dockerfile Command 상세  📄

* centos 에 올라간 python 이미지를 받아옵니다.

```
FROM centos/python-36-centos7
```

* 이후 현재 경로에 있는 폴더를 복사하고

```
ADD . $DEPLOY_HOME/
```

* 현재 프로젝트에서 사용하고 있는 Python Packages 를 설치한 뒤

```
RUN pip install --upgrade -r requirements.txt
```

* PORT 와 띄울 Worker 갯수를 환경변수로 셋팅하고,  Entry Point 로 `./docker-entry.sh`  를 지정해줍니다.

```
ENV PORT=8000 \
    NUM_WORKERS=4
    
ENTRYPOINT ["./docker-entry.sh"]
```
