Docker Review - docker部署Tomcat & Nginx

简介: Docker Review - docker部署Tomcat & Nginx

image.png

Docker 部署tomcat

搜索 tomcat

f4370ef3a30943b8bbdebc83ac58b8aa.png

下载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

访问下试试


897c1e1f6e194c9bb6568ec48c022e7c.png

不应该啊,看看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#



image.png


重新访问tomcat

刷新页面,无需重启容器

image.png


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: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 ~]#



外网访问:


6e489809c330446eb6765494f3fc8690.png


相关文章
|
3月前
|
应用服务中间件 网络安全 nginx
手把手教你使用 Docker 部署 Nginx 教程
本文详解Nginx核心功能与Docker部署优势,涵盖镜像拉取、容器化部署(快速、挂载、Compose)、HTTPS配置及常见问题处理,助力高效搭建稳定Web服务。
1358 4
|
6月前
|
关系型数据库 应用服务中间件 nginx
Docker一键安装中间件(RocketMq、Nginx、MySql、Minio、Jenkins、Redis)
本系列脚本提供RocketMQ、Nginx、MySQL、MinIO、Jenkins和Redis的Docker一键安装与配置方案,适用于快速部署微服务基础环境。
|
3月前
|
应用服务中间件 Linux nginx
在虚拟机Docker环境下部署Nginx的步骤。
以上就是在Docker环境下部署Nginx的步骤。需要注意,Docker和Nginix都有很多高级用法和细节需要掌握,以上只是一个基础入门级别的教程。如果你想要更深入地学习和使用它们,请参考官方文档或者其他专业书籍。
180 5
|
5月前
|
Java jenkins 应用服务中间件
结合Jenkins与Tomcat,实施Maven项目的自动构建和部署流程。
任何项目构建和部署的自动化流程,总离不开对各个环节精细把控与密切配合。涉及到源代码管理、构建工具、持续集成服务器以及最终的运行时环境的协调。通过上述简洁实用的步骤,可以实现Maven项目从源代码到运行状态的无缝过渡,进而提升软件开发的效率与质量。
338 0
|
8月前
|
应用服务中间件 Linux 网络安全
技术指南:如何把docsify项目部署到基于CentOS系统的Nginx中。
总结 与其他部署方法相比,将docsify项目部署到基于CentOS系统的Nginx中比较简单。以上步骤应当帮助你在不花费太多时间的情况下,将你的项目顺利部署到Nginx中。迈出第一步,开始部署你的docsify项目吧!
360 14
|
8月前
|
开发框架 Java 关系型数据库
在Linux系统中安装JDK、Tomcat、MySQL以及部署J2EE后端接口
校验时,浏览器输入:http://[your_server_IP]:8080/myapp。如果你看到你的应用的欢迎页面,恭喜你,一切都已就绪。
561 17
|
8月前
|
存储 安全 应用服务中间件
将下载的Nginx证书转换为Tomcat证书格式
好,可以看到,将Nginx证书转换为Tomcat证书的过程就像在烘焙一块蛋糕。你需要准备材料(证书),配备工具(OpenSSL, keytool),按照一定的步骤慎重制作,最后你就拥有了一块可以在浏览器中呈现出漂亮的安全状态的HTTPS蛋糕。就这么简单,明了,没有任何复杂的理论知识,就像在家庭厨房里烘焙的快乐一样。
368 16
|
关系型数据库 MySQL 应用服务中间件
|
Web App开发 应用服务中间件 nginx
saltstack批量部署并配置nginx
最近应别的部门要求研究了一下saltstack,感觉很好用哈!虽然我现在生产环境用的puppet,想以后逐渐用这个去替代puppet,至于ansible还没研究,以后有时间再看看吧! 一、Saltstack是什么? saltstack是一种全新的基础设施管理方式,部署轻松,在几分钟内可运行起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯。
2035 0
|
4月前
|
编解码 应用服务中间件 Linux
centos配置nginx-rtmp实现ffmpeg转码rtsp为rtmp视频流
centos配置nginx-rtmp实现ffmpeg转码rtsp为rtmp视频流
451 1