Docker Review - docker部署Tomcat Nginx
生活随笔
收集整理的這篇文章主要介紹了
Docker Review - docker部署Tomcat Nginx
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- Docker 部署tomcat
- 搜索 tomcat
- 下載tomcat
- 啟動tomcat
- 訪問tomcat
- 查看webapps & 修復問題
- 重新訪問tomcat
- Docker 部署Nginx
- 搜索 nginx
- 下載ng
- 啟動nginx
- 查看容器內的ng
- 訪問
Docker 部署tomcat
搜索 tomcat
下載tomcat
[root@VM-0-7-centos ~]# docker pull tomcat Using default tag: latest latest: Pulling from library/tomcat df5590a8898b: Pull complete 705bb4cb554e: Pull complete 519df5fceacd: Pull complete ccc287cbeddc: Pull complete 39a2961e8351: Pull complete 0287b7aa7f62: Pull complete 165d4a436d89: Pull complete 2b9d00974b45: Pull complete 5b60b035e686: Pull complete e521db7f7e29: Pull complete Digest: sha256:0d985ff1e6cb81cdf3139336d95acb995621a5c79dfb4a705bc18e1e54134164 Status: Downloaded newer image for tomcat:latest docker.io/library/tomcat:latest [root@VM-0-7-centos ~]#啟動tomcat
啟動 tomcat 容器,將容器的 8080 端口與外網的 8888端口進行映射
[root@VM-0-7-centos ~]# docker run -d --name artisanTomcat -p 8888:8080 tomcat 2a0e6e88661732a710d8a30d9fda6d73c25478fe352a59f520cb753da6442f7b [root@VM-0-7-centos ~]# [root@VM-0-7-centos ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2a0e6e886617 tomcat "catalina.sh run" 36 seconds ago Up 34 seconds 0.0.0.0:8888->8080/tcp, :::8888->8080/tcp artisanTomcat bb19cf9ced23 nginx "/docker-entrypoint.…" 22 minutes ago Up 22 minutes 0.0.0.0:7788->80/tcp, :::7788->80/tcp artisanNginx [root@VM-0-7-centos ~]#訪問tomcat
訪問下試試
不應該啊,看看Tomcat下的webapps
[root@VM-0-7-centos ~]# docker exec -it artisanTomcat /bin/bash root@2a0e6e886617:/usr/local/tomcat# ls -al total 176 drwxr-xr-x 1 root root 4096 Sep 29 11:23 . drwxr-xr-x 1 root root 4096 Sep 29 11:13 .. -rw-r--r-- 1 root root 18994 Sep 6 16:22 BUILDING.txt -rw-r--r-- 1 root root 6210 Sep 6 16:22 CONTRIBUTING.md -rw-r--r-- 1 root root 60269 Sep 6 16:22 LICENSE -rw-r--r-- 1 root root 2333 Sep 6 16:22 NOTICE -rw-r--r-- 1 root root 3372 Sep 6 16:22 README.md -rw-r--r-- 1 root root 6905 Sep 6 16:22 RELEASE-NOTES -rw-r--r-- 1 root root 16517 Sep 6 16:22 RUNNING.txt drwxr-xr-x 2 root root 4096 Sep 29 11:24 bin drwxr-xr-x 1 root root 4096 Oct 6 13:16 conf drwxr-xr-x 2 root root 4096 Sep 29 11:23 lib drwxrwxrwx 1 root root 4096 Oct 6 13:16 logs drwxr-xr-x 2 root root 4096 Sep 29 11:24 native-jni-lib drwxrwxrwx 2 root root 4096 Sep 29 11:23 temp drwxr-xr-x 2 root root 4096 Sep 29 11:23 webapps drwxr-xr-x 7 root root 4096 Sep 6 16:22 webapps.dist drwxrwxrwx 2 root root 4096 Sep 6 16:22 work root@2a0e6e886617:/usr/local/tomcat# cd webapps root@2a0e6e886617:/usr/local/tomcat/webapps# ls root@2a0e6e886617:/usr/local/tomcat/webapps# pwd /usr/local/tomcat/webapps root@2a0e6e886617:/usr/local/tomcat/webapps#查看webapps & 修復問題
進入 tomcat 容器 ,發現webapps 下面什么都沒有 , 阿里云鏡像 默認是最小的鏡像,所有不必要的都剔除了,保證最小可運行環境
將webapps.dist 目錄下的文件拷貝到 webapps下面 ,然后刷新頁面就可以看到tomcat頁面了
root@2a0e6e886617:/usr/local/tomcat# cd .. root@2a0e6e886617:/usr/local/tomcat# cp -r webapps.dist/* webapps root@2a0e6e886617:/usr/local/tomcat# cd webapps root@2a0e6e886617:/usr/local/tomcat/webapps# ls -al total 32 drwxr-xr-x 1 root root 4096 Oct 6 13:22 . drwxr-xr-x 1 root root 4096 Sep 29 11:23 .. drwxr-xr-x 3 root root 4096 Oct 6 13:22 ROOT drwxr-xr-x 15 root root 4096 Oct 6 13:22 docs drwxr-xr-x 7 root root 4096 Oct 6 13:22 examples drwxr-xr-x 6 root root 4096 Oct 6 13:22 host-manager drwxr-xr-x 6 root root 4096 Oct 6 13:22 manager root@2a0e6e886617:/usr/local/tomcat/webapps# root@2a0e6e886617:/usr/local/tomcat/webapps#重新訪問tomcat
刷新頁面,無需重啟容器
Docker 部署Nginx
搜索 nginx
[root@VM-0-7-centos ~]# docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 15588 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2069 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 818 [OK] jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 247 linuxserver/nginx An Nginx container, brought to you by LinuxS… 156 tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 141 [OK] jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 139 [OK] alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 108 [OK] nginxdemos/hello NGINX webserver that serves a simple page co… 73 [OK] privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 57 [OK] nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 55 nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 54 staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 24 [OK] nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 23 nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 20 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 … 15 centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13 bitwarden/nginx The Bitwarden nginx web server acting as a r… 11 flashspys/nginx-static Super Lightweight Nginx Image 10 [OK] mailu/nginx Mailu nginx frontend 9 [OK] navidonskis/nginx-php5.6 Docker nginx + php5.6 on Ubuntu 7 [OK] ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 2 [OK] wodby/nginx Generic nginx 1 [OK] arnau/nginx-gate Docker image with Nginx with Lua enabled on … 1 [OK]下載ng
[root@VM-0-7-centos ~]# docker pull nginx Using default tag: latest latest: Pulling from library/nginx 07aded7c29c6: Pull complete bbe0b7acc89c: Pull complete 44ac32b0bba8: Pull complete 91d6e3e593db: Pull complete 8700267f2376: Pull complete 4ce73aa6e9b0: Pull complete Digest: sha256:06e4235e95299b1d6d595c5ef4c41a9b12641f6683136c18394b858967cd1506 Status: Downloaded newer image for nginx:latest docker.io/library/nginx:latest啟動nginx
- -d 后臺啟動
- –name 給容器命名
- -p 宿主機端口:容器端口
查看容器內的ng
# 進入容器 [root@VM-0-7-centos ~]# docker exec -it artisanNginx /bin/bash root@bb19cf9ced23:/# 查找nginx root@bb19cf9ced23:/# whereis nginx nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx root@bb19cf9ced23:/# cd /etc/nginx root@bb19cf9ced23:/etc/nginx# ls conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params root@bb19cf9ced23:/etc/nginx## 查看配置文件 root@bb19cf9ced23:/etc/nginx# cat nginx.confuser 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; } root@bb19cf9ced23:/etc/nginx#訪問
本地訪問
[root@VM-0-7-centos ~]# curl localhost:7788 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } 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@VM-0-7-centos ~]#外網訪問:
總結
以上是生活随笔為你收集整理的Docker Review - docker部署Tomcat Nginx的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Docker Review - dock
- 下一篇: 软件级负载均衡器(LVS/HAProxy