Hikaru's notes

A collection of notes and resources

View the Project on GitHub HikaruMizoe/notes

読みだした理由

メモ

ためしに nginx を立ち上げてみる

docker run --rm --detach --publish 8080:80 --name web nginx:1.25.3

# 実行結果
Unable to find image 'nginx:1.25.3' locally # ローカルにnginx:1.25.3がないのでpullする
1.25.3: Pulling from library/nginx # nginx:1.25.3をDocker Hubからpullする
a1330b43d726: Pull complete # 各行で1つのレイヤをダウンロードしている。既存のレイヤに新しいレイヤを重ねる感じで開発できるらしい
504c1e01744e: Pull complete
5e8995dba715: Pull complete
330fd09f4306: Pull complete
74a4f808141d: Pull complete
d5181593591e: Pull complete
e1caac4eb9d2: Pull complete
Digest: sha256:c7a6ad68be85142c7fe1089e48faa1e7c7166a194caa9180ddea66345876b9d2

chapter-01\custom-nginx

レジストリにアップロードしてみる

Docker 公式のベストプラクティスの大事なところだけ

From golang:1.20.5-alpine3.18 as build-env # ビルド環境を指定
WORKDIR /go/src/app # 作業ディレクトリを指定
COPY . . # ソースコードをコンテナにコピー
RUN go build -o myapp # アプリケーションをビルド

FROM alpine:3.18 # 本番環境を指定
COPY --from=build-env /go/src/app/myapp /usr/local/bin/myapp # ビルドしたアプリケーションをコピー
CMD ["myapp"] # アプリケーションを実行するコマンド

簡単なサンプルアプリ起動に必要な知識

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
    - name: nginx
      image: nginx:1.25.3 # nginx のイメージを指定
      resources:
        requests:
          memory: "64Mi" # Podに割り当てるメモリ量
  ports:
    - port: 80 # Podのポート番号
      targetPort: 80 # コンテナのポート番号
      nodePort: 30080 # アプリのポート番号(適当なイフェメラルポートを指定)

Manifile 書いて、既存のクラスターに追加する

参考

トラブルシューティング

トラブルシューティングの概要

-