<返回更多

docker如何直接运行一个nginx应用

2022-07-27    阿文系统架构
加入收藏

一、Docker直接运行一个Nginx应用

# docker run -d -p 8080:80 nginxUnable to find image 'nginx:latest' locallylatest: Pulling from library/nginxa330b6cecb98: Pull completee0ad2c0621bc: Pull complete9e56c3e0e6b7: Pull complete09f31c94adc6: Pull complete32b26e9cdb83: Pull complete20ab512bbb07: Pull completeDigest: sha256:853b221d3341add7aaadf5f81dd088ea943ab9c918766e295321294b035f3f3eStatus: Downloaded newer image for nginx:latest6b5ac123787fddd00f598724cef9e8b447b16fdb9d86db6c0125c522f7f6bfc0

注:

1、docker将自动下载标签为latest的image

2、分层下载

2、自动创建一个容器:
6b5ac123787fddd00f598724cef9e8b447b16fdb9d86db6c0125c522f7f6bfc0

二、查看容器的ID和端口映射

# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES6b5ac123787f nginx "/docker-entrypoint.…" 10 minutes ago Up 10 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp hungry_elbakyan

 

图1

 

图2

 

三、测试

1.访问 nginx

 

 

2.查看日志

# docker logs 6b5ac123787f/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.sh10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf10-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 up2021/09/18 07:29:05 [notice] 1#1: using the "epoll" event method2021/09/18 07:29:05 [notice] 1#1: nginx/1.21.32021/09/18 07:29:05 [notice] 1#1: built by gcc 8.3.0 (Debian 8.3.0-6)2021/09/18 07:29:05 [notice] 1#1: OS: linux 3.10.0-1160.42.2.el7.x86_642021/09/18 07:29:05 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:10485762021/09/18 07:29:05 [notice] 1#1: start worker processes2021/09/18 07:29:05 [notice] 1#1: start worker process 322021/09/18 07:29:05 [notice] 1#1: start worker process 332021/09/18 07:29:05 [notice] 1#1: start worker process 342021/09/18 07:29:05 [notice] 1#1: start worker process 35172.17.0.1 - - [18/Sep/2021:07:41:56 +0000] "GET / HTTP/1.1" 200 615 "-" "Mozilla/5.0 (windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/93.0.4577.63 Safari/537.36" "172.16.5.199"2021/09/18 07:41:56 [error] 32#32: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "172.16.5.181:8080", referrer: "http://172.16.5.181:8080/"172.17.0.1 - - [18/Sep/2021:07:41:56 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://172.16.5.181:8080/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36" "172.16.5.199"

本文结束

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>