LoginSignup
0
0

More than 1 year has passed since last update.

Docker:nginxのデタッチドモードのON・OFFによるインストールや関連コマンドなど

Last updated at Posted at 2023-02-18

nginxのコンテナを立ち上げるコマンド

// 公式 → docker run --name some-nginx -d -p 8080:80 some-content-nginx
docker run --name<コンテナ名> -d \
 -p <ホスト側のポート番号>:<コンテナ側のポート番号> <イメージ名>

バックスラッシュ

改行が目的。コマンドが長すぎて見づらくなる視認性確保のため。

--name<コンテナ名> 

独自の命名をする。識別に必要。

-d オプション

デタッチドモード。コンテナの実行をバックグラウンドで実施させる。デーモンのような常駐型のプログラムをDockerコンテナで実行する場合はこれを利用すること多し。
これを指定せずに実行するとフォアグラウンドで実行されるため、終了するまで他の操作ができなくなる。

-p オプション

コンテナのポートをコンテナ外へ設定する。

Dockerにnginxをデタッチドモードにしたりしなかったりの確認を含めた体験

Docker Hubからデタッチドモードでnginxをインストール

※ローカルのポート番号と被ってたら変更必要。

docker run --name test-nginx -d -p 8080:80 nginx

非デタッチドモードでインストールした場合の挙動を知る

この確認のために、上でデタッチドモードでインストールしたnginxを一旦削除する。
まず、削除の前に停止せねば。

docker stop test-nginx

しかし、このコマンドで停止したが、停止ができたのか不明瞭なメッセージしか出ない。
「test-nginx」
としか表示されないのだ。
よって、停止から開始を行ってみるしかない。

停止したコンテナを再び開始

docker run text-nginx

すると、何と起動しない。
以下のメッセージが出る。

Unable to find image 'test-nginx:latest' locally
docker: Error response from daemon: pull access denied for test-nginx, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

うん?? そういえば、昨日ログインしたが、今日はログインしていない。
ならばなぜインストールはできて、停止もできたのに、なぜか石だけができないのか??
全く理解不能。仕方なく、Warpのありがたいサジェスト補助機能でログインコマンド込みのコマンドを打つ。

docker login && docker run test-nginx

すると、ログイン成功と出る。

Authenticating with existing credentials...
Login Succeeded

Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/
Unable to find image 'test-nginx:latest' locally
docker: Error response from daemon: pull access denied for test-nginx, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

ログイン成功と言いながら、一方でデーモンからエラー応答と言う。
理解不能。
さらにおかしいのは、サジェストコマンドを見るとログイン記述が繰り返されている。
以下。

docker login && docker login && docker run test-nginx

一応信じてコマンド打つとやはりだめ。

Authenticating with existing credentials...
Login Succeeded

Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/
Authenticating with existing credentials...
Login Succeeded

Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/
Unable to find image 'test-nginx:latest' locally
docker: Error response from daemon: pull access denied for test-nginx, repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

さらに、今度はサジェストがログインを三つ繰り返すコマンドを提案してくる。あり得ない。

docker login && docker login && docker login && docker run test-nginx

全く意味不明、理科不能なため、停止されたことを確認したかったので開始を試みたわけだが、止める。
続けてコンテナを削除してみる。

docker rm test-nginx

すると、停止時と同様の表示になり、またもや削除ができたのかどうかが不透明な表示だった。
停止時はちゃんと停止していたようなので、この削除でも信じて先へ進む。

test-nginx

非デタッチドモードでインストール

docker run --name test-nginx -p 8080:80 nginx

すると、以下の大量の出力がなされたが、挙動の流れが紹介されており、結局インストールはうまくいったと思われた。

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2023/02/19 02:08:39 [notice] 1#1: using the "epoll" event method
2023/02/19 02:08:39 [notice] 1#1: nginx/1.23.3
2023/02/19 02:08:39 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2023/02/19 02:08:39 [notice] 1#1: OS: Linux 5.15.49-linuxkit
2023/02/19 02:08:39 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2023/02/19 02:08:39 [notice] 1#1: start worker processes
2023/02/19 02:08:39 [notice] 1#1: start worker process 29
2023/02/19 02:08:39 [notice] 1#1: start worker process 30
2023/02/19 02:08:39 [notice] 1#1: start worker process 31
2023/02/19 02:08:39 [notice] 1#1: start worker process 32
172.17.0.1 - - [19/Feb/2023:02:10:53 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36" "-"

ChatGPTによると以下。

最初に、/docker-entrypoint.d/ディレクトリが空でないため、構成を行うというメッセージが表示されます。次に、/docker-entrypoint.d/ディレクトリ内のシェルスクリプトが順番に実行され、IPv6での接続を有効にするスクリプト、環境変数をテンプレートに反映するスクリプト、およびworkerプロセスの調整を行うスクリプトが順番に実行されます。最後に、nginxのバージョン情報や起動時の設定が表示され、workerプロセスが起動されたことが確認されています。
このログからは、nginxがインストールされたことが示唆されています。特にエラーメッセージはなく、nginxのバージョン情報が表示されています。また、workerプロセスも正常に起動していることが確認されています。したがって、このログからは、nginxが正常にインストールされたと考えられます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0