DockerでNginxを動かす実践的な例を通して、コンテナ化の基本を身につけます。静的サイトの配信からカスタム設定まで解説します。
Nginxコンテナの起動
docker run -d -p 8080:80 --name mynginx nginx:latest
docker run -d -p 8080:80 -v $(pwd)/html:/usr/share/nginx/html:ro --name mynginx nginx:latestカスタム設定でDockerfile作成
FROM nginx:latest
COPY nginx.conf /etc/nginx/nginx.conf
COPY html/ /usr/share/nginx/html/
EXPOSE 80docker build -t custom-nginx .
docker run -d -p 80:80 custom-nginxdocker-composeでNginx+アプリを構成
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- app
app:
build: .
expose:
- "3000"まとめ
- nginx:latestイメージで簡単にWebサーバーをコンテナ化できる
- -vでホストのHTMLをコンテナに共有して静的サイトを配信できる
- docker composeでNginx+バックエンドの構成を簡単に管理できる



コメント