From 3665810dc0d269aa0bee832de3acfd95aefae0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BF=E3=81=AD=E3=81=8E=E3=81=97=E3=82=8C=E3=81=84?= <68362169+minegishirei@users.noreply.github.com> Date: Mon, 15 May 2023 18:47:50 +0900 Subject: [PATCH] =?UTF-8?q?Signed-off-by:=20=E3=81=BF=E3=81=AD=E3=81=8E?= =?UTF-8?q?=E3=81=97=E3=82=8C=E3=81=84=20<68362169+minegishirei@users.nore?= =?UTF-8?q?ply.github.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx/docker-compose.yml | 13 ++++ nginx/nginx/Dockerfile | 1 + nginx/nginx/Readme.md | 117 ++++++++++++++++++++++++++++++++ nginx/nginx/conf.d/default.conf | 8 +++ nginx/nginx/html/index.html | 3 + 5 files changed, 142 insertions(+) create mode 100644 nginx/docker-compose.yml create mode 100644 nginx/nginx/Dockerfile create mode 100644 nginx/nginx/Readme.md create mode 100644 nginx/nginx/conf.d/default.conf create mode 100644 nginx/nginx/html/index.html diff --git a/nginx/docker-compose.yml b/nginx/docker-compose.yml new file mode 100644 index 0000000..83ed0c6 --- /dev/null +++ b/nginx/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3" + +services: + nginx: + container_name: nginx + build: + ./nginx + ports: + - "80:80" + - "443:443" + volumes: + - ./nginx/html:/usr/share/nginx/html + - ./nginx/conf.d:/etc/nginx/conf.d diff --git a/nginx/nginx/Dockerfile b/nginx/nginx/Dockerfile new file mode 100644 index 0000000..16882d3 --- /dev/null +++ b/nginx/nginx/Dockerfile @@ -0,0 +1 @@ +FROM nginx:latest \ No newline at end of file diff --git a/nginx/nginx/Readme.md b/nginx/nginx/Readme.md new file mode 100644 index 0000000..ead5b2d --- /dev/null +++ b/nginx/nginx/Readme.md @@ -0,0 +1,117 @@ + + + +## Compose sample application + +### Use with Docker Development Environments + +You can open this sample in the Dev Environments feature of Docker Desktop version 4.12 or later. + +[Open in Docker Dev Environments Open in Docker Dev Environments](https://open.docker.com/dashboard/dev-envs?url=https://github.com/docker/awesome-compose/tree/master/nginx-golang-mysql) + +### Simple Nginx HTTP Server + +Project structure: + +``` +│ docker-compose.yml +│ Readme.md +│ +└─nginx + │ Dockerfile + │ + ├─conf.d + │ default.conf + │ + └─html + index.html +``` + +[_compose.yaml_](compose.yaml) +```yaml +version: "3" + +services: + nginx: + container_name: nginx + build: + ./nginx + ports: + - "80:80" + - "443:443" + volumes: + - ./nginx/html:/usr/share/nginx/html + - ./nginx/conf.d:/etc/nginx/conf.d +``` + + +## Deploy with docker compose + +```shell +$ docker compose up -d +[+] Running 2/0 + ✔ Network nginx_default Created 0.0s + ✔ Container nginx Created 0.0s +Attaching to nginx +nginx | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration +nginx | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ +nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh +nginx | 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf +nginx | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version +nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh +nginx | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh +nginx | /docker-entrypoint.sh: Configuration complete; ready for start up +nginx | 2023/05/15 09:19:08 [notice] 1#1: using the "epoll" event method +nginx | 2023/05/15 09:19:08 [notice] 1#1: nginx/1.23.4 +nginx | 2023/05/15 09:19:08 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) +nginx | 2023/05/15 09:19:08 [notice] 1#1: OS: Linux 5.15.90.1-microsoft-standard-WSL2 +nginx | 2023/05/15 09:19:08 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker processes +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 28 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 29 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 30 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 31 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 32 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 33 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 34 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 35 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 36 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 37 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 38 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 39 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 40 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 41 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 42 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 43 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 44 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 45 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 46 +nginx | 2023/05/15 09:19:08 [notice] 1#1: start worker process 47 +``` + + +## URL + +http://localhost/index.html + + +## Expected result + +Listing containers must show three containers running and the port mapping as below: +```shell +$ docker compose ps +NAME COMMAND SERVICE STATUS PORTS +nginx-golang-mysql-backend-1 "/code/bin/backend" backend running +nginx-golang-mysql-db-1 "docker-entrypoint.s…" db running (healthy) 3306/tcp +nginx-golang-mysql-proxy-1 "/docker-entrypoint.…" proxy running 0.0.0.0:80->80/tcp +l_db_1 +``` + +After the application starts, navigate to `http://localhost/index.html` in your web browser or run: + +Stop and remove the containers +```shell +$ docker compose down -v +``` + + diff --git a/nginx/nginx/conf.d/default.conf b/nginx/nginx/conf.d/default.conf new file mode 100644 index 0000000..188b1d0 --- /dev/null +++ b/nginx/nginx/conf.d/default.conf @@ -0,0 +1,8 @@ +server { + listen 80; + server_name localhost; + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } +} \ No newline at end of file diff --git a/nginx/nginx/html/index.html b/nginx/nginx/html/index.html new file mode 100644 index 0000000..35704fe --- /dev/null +++ b/nginx/nginx/html/index.html @@ -0,0 +1,3 @@ +

+ hello world! +

\ No newline at end of file