共计 5661 个字符,预计需要花费 15 分钟才能阅读完成。
人生有涯,学海无涯
一、Docker 装置 Nginx
# 1、搜寻 nginx
[root@jiangwang home]# docker search nginx
NAME DESCRIPTION STARS
nginx Official build of Nginx. 14539
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1981
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 809
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 158
linuxserver/nginx An Nginx container, brought to you by LinuxS… 142
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 115
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 97
bitnami/nginx Bitnami nginx Docker Image 94
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 89
jasonrivers/nginx-rtmp Docker images to host RTMP streams using NGI… 88
nginxdemos/hello NGINX webserver that serves a simple page co… 67
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 49
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 48
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 31
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 19
staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 19
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 16
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 15
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
flashspys/nginx-static Super Lightweight Nginx Image 9
bitwarden/nginx The Bitwarden nginx web server acting as a r… 9
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 8
mailu/nginx Mailu nginx frontend 8
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 2
wodby/nginx Generic nginx
# 2、下载 nginx 镜像
[root@jiangwang home]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a076a628af6f: Pull complete
0732ab25fa22: Pull complete
d7f36f6fe38f: Pull complete
f72584a26f32: Pull complete
7125e4df9063: Pull complete
Digest: sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
# 3、启动 nginx
# -d 后盾启动
# --name 给容器命名
# -p 宿主机端口:容器端口
[root@jiangwang home]# docker run -d --name nginx01 -p 3344:80 nginx
0692aec62ba9f2487653629280becb8bcb915605faee12ee3bd3b8d5de148c32
[root@jiangwang home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0692aec62ba9 nginx "/docker-entrypoint.…" 7 seconds ago Up 6 seconds 0.0.0.0:3344->80/tcp nginx01
# 本地拜访一下试试
[root@jiangwang home]# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@jiangwang home]#
# 进入容器
[root@jiangwang home]# docker exec -it nginx01 /bin/bash
root@0692aec62ba9:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@0692aec62ba9:/# cd /etc/nginx
root@0692aec62ba9:/etc/nginx# ls
conf.d koi-utf mime.types nginx.conf uwsgi_params
fastcgi_params koi-win modules scgi_params win-utf
root@0692aec62ba9:/etc/nginx#
# 进行容器的运行
root@0692aec62ba9:/etc/nginx# exit # 退出容器
exit
[root@jiangwang home]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0692aec62ba9 nginx "/docker-entrypoint.…" 9 minutes ago Up 9 minutes 0.0.0.0:3344->80/tcp nginx01
[root@jiangwang home]# docker stop 0692aec62ba9 # 进行容器
0692aec62ba9
在浏览器上用公网拜访一下,测试看看,后果也是能够拜访到的,这外面前提是你的 3344 端口号曾经开发了,只有是开发的端口号都能够进行测试。
二、Docker 装置 Tomcat
# 下载 tomcat 镜像
[root@jiangwang home]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
Digest: sha256:94cc18203335e400dbafcd0633f33c53663b1c1012a13bcad58cced9cd9d1305
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
[root@jiangwang home]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 9.0 040bdb29ab37 7 weeks ago 649MB
tomcat latest 040bdb29ab37 7 weeks ago 649MB
nginx latest f6d0b4767a6c 8 weeks ago 133MB
centos latest 300e315adb2f 3 months ago 209MB
# 启动 tomcat 容器,将容器的 8080 端口与外网的 3355 端口进行映射
[root@jiangwang home]# docker run -d -p 3355:8080 --name tomcat01 tomcat
1a0d54668dd61afb333aa0854e1c0ceafca3c8f695f820089d28eefa4977f0f6
[root@jiangwang home]#
浏览器上查看一下:后果是 404,阐明
# 进入 tomcat 容器,发现 webapps 上面什么都没有,这个是阿里云镜像的起因,默认是最小的镜像,所有不必要的都剔除了,保障最小可运行环境
[root@jiangwang home]# docker exec -it tomcat01 /bin/bash
root@1a0d54668dd6:/usr/local/tomcat# ls -al
total 176
drwxr-xr-x 1 root root 4096 Jan 13 08:25 .
drwxr-xr-x 1 root root 4096 Jan 13 08:19 ..
-rw-r--r-- 1 root root 18982 Dec 3 11:48 BUILDING.txt
-rw-r--r-- 1 root root 5409 Dec 3 11:48 CONTRIBUTING.md
-rw-r--r-- 1 root root 57092 Dec 3 11:48 LICENSE
-rw-r--r-- 1 root root 2333 Dec 3 11:48 NOTICE
-rw-r--r-- 1 root root 3257 Dec 3 11:48 README.md
-rw-r--r-- 1 root root 6898 Dec 3 11:48 RELEASE-NOTES
-rw-r--r-- 1 root root 16507 Dec 3 11:48 RUNNING.txt
drwxr-xr-x 2 root root 4096 Jan 13 08:25 bin
drwxr-xr-x 1 root root 4096 Mar 9 11:39 conf
drwxr-xr-x 2 root root 4096 Jan 13 08:25 lib
drwxrwxrwx 1 root root 4096 Mar 9 11:39 logs
drwxr-xr-x 2 root root 4096 Jan 13 08:25 native-jni-lib
drwxrwxrwx 2 root root 4096 Jan 13 08:25 temp
drwxr-xr-x 2 root root 4096 Jan 13 08:25 webapps
drwxr-xr-x 7 root root 4096 Dec 3 11:45 webapps.dist
drwxrwxrwx 2 root root 4096 Dec 3 11:43 work
root@1a0d54668dd6:/usr/local/tomcat# cd webapps
root@1a0d54668dd6:/usr/local/tomcat/webapps# ls
root@1a0d54668dd6:/usr/local/tomcat/webapps#
# 将 webapps.dist 目录下的文件拷贝到 webapps 上面,而后刷新页面就能够看到 tomcat 页面了
root@1a0d54668dd6:/usr/local/tomcat/webapps# cd ..
root@1a0d54668dd6:/usr/local/tomcat# cd webapps.dist
root@1a0d54668dd6:/usr/local/tomcat/webapps.dist# ls
ROOT docs examples host-manager manager
root@1a0d54668dd6:/usr/local/tomcat/webapps.dist# cd ..
root@1a0d54668dd6:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@1a0d54668dd6:/usr/local/tomcat# cd webapps
root@1a0d54668dd6:/usr/local/tomcat/webapps# ls
ROOT docs examples host-manager manager
root@1a0d54668dd6:/usr/local/tomcat/webapps#
正文完