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


相关文章
|
21天前
|
存储 测试技术 Linux
【Docker项目实战】使用Docker部署bender个人仪表板
【4月更文挑战第2天】使用Docker部署bender个人仪表板
33 1
|
22天前
|
前端开发 应用服务中间件 nginx
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
91 0
|
2天前
|
Ubuntu Linux 测试技术
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试(下)
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试
22 1
|
4天前
|
存储 测试技术 文件存储
【Docker项目实战】使用Docker部署Sun-Panel导航面板
【4月更文挑战第19天】使用Docker部署Sun-Panel导航面板
54 7
|
7天前
|
应用服务中间件 Linux 开发工具
如何在阿里云服务器快速搭建部署Nginx环境
以下是内容的摘要: 本文档主要介绍了在阿里云上购买和配置服务器的步骤,包括注册阿里云账号、实名认证、选择和购买云服务器、配置安全组、使用Xshell和Xftp进行远程连接和文件传输,以及安装和配置Nginx服务器的过程。在完成这些步骤后,你将能够在服务器上部署和运行自己的网站或应用。
|
7天前
|
测试技术 Linux 网络安全
【好玩的开源项目】使用Docker部署SyncTV视频同步和共享平台
【4月更文挑战第16天】使用Docker部署SyncTV视频同步和共享平台
45 1
|
12天前
|
测试技术 Linux 数据安全/隐私保护
【Docker项目实战】使用Docker部署Seatsurfing预订座位系统
【4月更文挑战第12天】使用Docker部署Seatsurfing预订座位系统
37 3
|
15天前
|
JavaScript 前端开发 Docker
全栈开发实战:结合Python、Vue和Docker进行部署
【4月更文挑战第10天】本文介绍了如何使用Python、Vue.js和Docker进行全栈开发和部署。Python搭配Flask创建后端API,Vue.js构建前端界面,Docker负责应用的容器化部署。通过编写Dockerfile,将Python应用构建成Docker镜像并运行,前端部分使用Vue CLI创建项目并与后端交互。最后,通过Nginx和另一个Dockerfile部署前端应用。这种组合提升了开发效率,保证了应用的可维护性和扩展性,适合不同规模的企业使用。
|
15天前
|
Linux Shell 虚拟化
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
26 0
|
15天前
|
存储 Linux Shell
centos 部署docker容器 安装 、基本使用方法(一)
centos 部署docker容器 安装 、基本使用方法(一)
29 0