1.使用 docker serach nginx 查找nginx镜像
[root@localhost ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 11254 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1582 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 706 [OK]
jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 500 [OK]
webdevops/php-nginx Nginx with PHP-FPM 125 [OK]
zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 95 [OK]
bitnami/nginx Bitnami nginx Docker Image 65 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 58
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 50 [OK]
zabbix/zabbix-web-nginx-pgsql Zabbix frontend based on Nginx with PostgreS… 31 [OK]
tobi312/rpi-nginx NGINX on Raspberry Pi / ARM 26 [OK]
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 17
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 14 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 13 [OK]
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 12 [OK]
wodby/drupal-nginx Nginx for Drupal container image 12 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 10
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 7
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 4
1science/nginx Nginx Docker images that include Consul Temp… 4 [OK]
mailu/nginx Mailu nginx frontend 3 [OK]
travix/nginx NGinx reverse proxy 2 [OK]
toccoag/openshift-nginx Nginx reverse proxy for Nice running on same… 1 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 0 [OK]
wodby/nginx Generic nginx 0 [OK]
2.拉取镜像命令: docker pull nginx 获取之后默认tag为latest
[root@localhost ~]# docker pull nginx
Using default tag: latest
3.查看获取的镜像 docker images nginx
[root@localhost ~]# docker images nginx
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 881bd08c0b08 6 weeks ago 109MB
4.创建nginx容器
命令:docker run --name nginx_test-d -m 1024M -p 80:80 nginx
(如果要创建多个tomcat容器 一定要修改name和主机端口)
说明:
--name 容器名称
-d 后台运行
-m 设置容器使用内存最大值;
-p 端口映射,格式为:主机(宿主)端口:容器端口
[root@JaxWan local]# docker run --name jax-nginx -d -m 1024M -p 80:80 nginx
5.查看运行状态 docker ps
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2cec1acd172 redis:latest "docker-entrypoint.s…" 3 days ago Up 6 hours 0.0.0.0:6379->6379/tcp jax_redis
4068c1c383f1 tomcat:7.0.92 "catalina.sh run" 3 weeks ago Up 6 hours 0.0.0.0:8455->8080/tcp checktomcat
6f9726681e83 mysql:5.7.19 "docker-entrypoint.s…" 3 weeks ago Up 6 hours 0.0.0.0:3306->3306/tcp mysql
5eb927494115 nginx "nginx -g 'daemon of…" 5 weeks ago Up 6 hours 0.0.0.0:80->80/tcp nginx_test
f42ef6cc1aca tomcat:7.0.92 "catalina.sh run" 5 weeks ago Up 6 hours 0.0.0.0:8083->8080/tcp tomcat3
6. 进入nginx容器修改/etc/nginx/nginx.conf配置
命令:docker exec -it 容器名称(容器ID) /bin/bash
进入/etc/nginx目录下,修改nginx.conf文件
[root@localhost ~]# docker exec -it nginx_test /bin/bash
root@5eb927494115:/# cd etc/nginx/
root@5eb927494115:/etc/nginx# vim nginx.conf
然后在nginx.conf文件添加以下配置:
server {
listen 80;
server_name nginx2tomcat1;
location /test {
proxy_pass http://192.168.29.24:8082;
}
}
附上我的nginx.conf文件全部内容
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
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;
server {
listen 80;
server_name nginx2tomcat1;
location /test {
proxy_pass http://192.168.29.24:8082;
}
}
include /etc/nginx/conf.d/*.conf;
}
7.修改完毕后退出重启nginx
退出命令(只是退出nginx): exit
root@5eb927494115:/etc/nginx# exit
exit
[root@localhost ~]#
重启nginx: docker restart 容器名称(容器ID)
[root@localhost ~]# docker restart nginx_test
8.浏览器查看代理是否成功
首先查看192.168.29.24:8082
然后查看192.168.29.24/test
9.可以选择安装vim编辑器
安装教程:https://blog.csdn.net/buyaopingbixiazai/article/details/89330848