引言
如果对Docker不太熟悉的小伙伴们可以先去看一下Docker入门,再来看这篇文章哟!
https://blog.youkuaiyun.com/m0_53559551/article/details/121358336
那么如果是从我上一篇Docker入门文章过来的或者是对Docker有个基本了解的小伙伴们现在跟我一起来了解一下在Docker中部署Nginx的步骤吧。
步骤一:搜索Nginx镜像
PS C:\Users\ASUS> docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 15839 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2096 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 819 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 279
linuxserver/nginx An Nginx container, brought to you by LinuxS… 160
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 145 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 143 [OK]
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 110 [OK]
jasonrivers/nginx-rtmp Docker images to host RTMP streams using NGI… 95 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 78 [OK]
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 60 [OK]
nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 57
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 54
staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 25 [OK]
nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 25
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 22
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19 [OK]
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 16
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
raulr/nginx-wordpress Nginx front-end for the official wordpress:f… 13 [OK]
mailu/nginx Mailu nginx frontend 9 [OK]
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 3 [OK]
wodby/nginx Generic nginx 1 [OK]
arnau/nginx-gate Docker image with Nginx with Lua enabled on … 1 [OK]
步骤二:下载镜像
PS C:\Users\ASUS> docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
eff15d958d66: Pull complete
1e5351450a59: Pull complete
2df63e6ce2be: Pull complete
9171c7ae368c: Pull complete
020f975acd28: Pull complete
266f639b35ad: Pull complete
Digest: sha256:097c3a0913d7e3a5b01b6c685a60c03632fc7a2b50bc8e35bcaa3691d788226e
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
步骤三:运行镜像
PS C:\Users\ASUS> docker run -d --name nginx01 -p 3344:80 nginx
8b5827a8d365c7eeb41d48ec418a319b57bd2177a8e4b835c734b8032a568a50
步骤四:修改配置
PS C:\Users\ASUS> docker exec -it nginx01 /bin/bash
root@8b5827a8d365:/# ls
bin dev docker-entrypoint.sh home lib64 mnt proc run srv tmp var
boot docker-entrypoint.d etc lib media opt root sbin sys usr
root@8b5827a8d365:/# cd etc
root@8b5827a8d365:/etc# ls
adduser.conf debian_version group- issue.net mke2fs.conf passwd rc6.d ssl
alternatives default gshadow kernel motd passwd- rcS.d subgid
apt deluser.conf gshadow- ld.so.cache mtab profile resolv.conf subuid
bash.bashrc dpkg gss ld.so.conf netconfig profile.d rmt systemd
bindresvport.blacklist e2scrub.conf host.conf ld.so.conf.d nginx rc0.d security terminfo
ca-certificates environment hostname libaudit.conf nsswitch.conf rc1.d selinux timezone
ca-certificates.conf fonts hosts localtime opt rc2.d shadow ucf.conf
cron.d fstab init.d login.defs os-release rc3.d shadow- update-motd.d
cron.daily gai.conf inputrc logrotate.d pam.conf rc4.d shells xattr.conf
debconf.conf group issue machine-id pam.d rc5.d skel
root@8b5827a8d365:/etc# cat nginx.conf
cat: nginx.conf: No such file or directory
root@8b5827a8d365:/etc# cd nginx
root@8b5827a8d365:/etc/nginx# cat nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
步骤五:运行测试
访问地址:localhost:3344