Docker:安装和关联命令中的nginx的开启和关闭分离模式

启动nginx容器的命令

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

反斜杠

为了保证命令的可读性,换行是必要的。

–容器名称<コンテナ名>

进行独立的命名。这是为了区分和识别的必要步骤。

-d 选项

脱离模式。将容器在后台运行。在Docker容器中运行守护程序的情况下,经常使用此选项。
如果不指定此选项进行运行,则会在前台运行,直到完成后无法进行其他操作。

-p选项

将容器的端口设置到容器外部。

包含了对Docker中Nginx的分离模式确认的体验。

在Docker Hub上使用分离模式安装nginx

如果与本地端口号重复,则需要进行更改。

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

了解非分离式安装模式下的行为

为了进行这个确认操作,需要先将之前以分离模式安装的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/目录中的shell脚本,其中包括启用IPv6连接的脚本、将环境变量应用于模板的脚本以及调整worker进程的脚本。最后,显示nginx的版本信息和启动时的设置,并确认worker进程已启动。

从这个日志中可以推断出nginx已安装。特别是没有错误消息,显示了nginx的版本信息。此外,还确认了worker进程正常启动。因此,可以认为nginx已成功安装。

广告
将在 10 秒后关闭
bannerAds