本ドキュメントのゴール
-
Dockerを使ってNGINXを稼働させる
-
NGINXを稼働させるWebサーバー内のHTMLファイルを表示するところまで
環境
-
ハードウェア
-
Raspberry Pi 4
-
-
OS
-
Ubuntu 24.04.1 LTS
-
-
前提条件
-
DockerおよびDocker Composeのインストール済みであること
-
手順
NGINXコンテナの起動
-
コンテナ用のディレクトリを作成
$ mkdir -p docker/nginx_sample $ cd docker/nginx_sample -
任意のディレクトリに`docker-compose.yml`を作成
version: "3" services: nginx: container_name: nginx image: nginx:latest build: ./nginx ports: - "14080:80" volumes: - .nginx/html:/usr/share/nginx/html - .nginx/conf.d:/etc/nginx/conf.d # nginxのconf.dをマウント -
マウント用のフォルダを作成
$ mkdir -p ./nginx/html $ mkdir -p ./nginx/conf.d -
confディレクトリにnginxのconfファイルを作成
$ nano ./nginx/conf.d/default.conf -
confファイルを編集する
server { listen 80; server_name localhost; location / { # docker内のディレクトリを指定 root /usr/share/nginx/html; index index.html index.htm; } } -
HTMLファイルを作成する
$ nano ./nginx/html/index.html -
HTMLファイルを編集する
<!DOCTYPE html> <html> <head> <title>Welcome to NGINX</title> </head> <body> <h1>Hello from NGINX running in Docker Compose!</h1> </body> </html> -
コンテナを起動する
$ docker compose up -d -
14080番ポートにアクセスして、
index.htmlの内容が表示されたことを確認