# Docker File

### Docker File 官方說明

[Dockerfile reference | Docker Documentation](https://docs.docker.com/engine/reference/builder/)

官方各類型docker file 專案連結(可找到專案git repo)

[official-images/library at master · docker-library/official-images · GitHub](https://github.com/docker-library/official-images/tree/master/library)

[![image-1645294864450.png](https://bookstack.treemanou.com/uploads/images/gallery/2022-02/scaled-1680-/xIH3UQ3k7ZQ3bYys-image-1645294864450.png)](https://bookstack.treemanou.com/uploads/images/gallery/2022-02/xIH3UQ3k7ZQ3bYys-image-1645294864450.png)

---

### Build Dockerfile

```shell
# docker image build -t {name}:{tag} {dokerfile 目錄}
docker image build -t hello_py:v1 .
```

### Docker File 結構

```INI
# 基礎鏡像檔
FROM ubuntu:21.04
# 環境變數
ENV VERSION=2.0.1
# 執行命令(可在執行容器的時候使用其他命覆蓋)
RUN apt-get update && \
    apt-get install -y wget && \
    wget https://github.com/ipinfo/cli/releases/download/ipinfo-${VERSION}/ipinfo_${VERSION}_linux_amd64.tar.gz && \
    tar zxf ipinfo_${VERSION}_linux_amd64.tar.gz && \
    mv ipinfo_${VERSION}_linux_amd64 /usr/bin/ipinfo && \
    rm -rf ipinfo_${VERSION}_linux_amd64.tar.gz
# 移動到當前目錄
WORKDIR /app
# 複製檔案
COPY hello.py /app/hello.py
# 複製檔案(如果是壓縮檔會自行解壓縮，一般來說還是用COPY)
ADD hello.tar.gz /app/
# 執行命令(無法覆蓋)
ENTRYPOINT ["echo", "hello docker"]
```