- 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 宿主机端口:容器端口
[root@VM-0-7-centos ~]# docker run -d --name artisanNginx -p 7788:80 nginx bb19cf9ced237313ef6cc0f332b1ed0f4ad8632c14a719de801ceb539ce41576 [root@VM-0-7-centos ~]# [root@VM-0-7-centos ~]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bb19cf9ced23 nginx "/docker-entrypoint.…" 3 seconds ago Up 3 seconds 0.0.0.0:7788->80/tcp, :::7788->80/tcp artisanNginx [root@VM-0-7-centos ~]# [root@VM-0-7-centos ~]# [root@VM-0-7-centos ~]#查看容器内的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.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;
}
root@bb19cf9ced23:/etc/nginx#
访问
本地访问
[root@VM-0-7-centos ~]# curl localhost:7788Welcome to nginx! Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.Thank you for using nginx.
[root@VM-0-7-centos ~]#
外网访问:



