2022/10/28

Dockerfileの書き方

# イメージ名:タグ名
FROM nginx:1.21

# メタデータ
LABEL maintainer="Namae Myouzi <mail@example.com>"

# 実行ユーザー
USER root

# ディレクトリ移動
WORKDIR /

# ローカルファイルをコンテナ内にコピーする
## 設定ファイル
COPY ./default.conf /etc/nginx/conf.d/
## コンテンツ
COPY ./*.html /var/www/html/
## 証明書
COPY ./ssl /etc/nginx/ssl

# イメージ作成時に実行するコマンド
RUN \
  apt-get update \
  && apt-get upgrade -y \
  && apt-get autoremove -y

# コンテナ実行時に実行するコマンド
## 上書き不可
ENTRYPOINT ["/usr/bin/date"]
## 上書き可能
CMD ["/usr/bin/date"]

# ListenPort
EXPOSE 80 443

# HealthCheck
HEALTHCHECK \
  --interval=30s \
  --timeout=10s \
  --start-period=60s \
  --retries=2 \
  CMD curl -f http://localhost/ || exit 1