一、docker安装Nginx
1.1 搜索Nginx镜像
[root@iZwz939qj61dxuoca8vryhZ ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 16250 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 2114 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 821 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 322
linuxserver/nginx An Nginx container, brought to you by LinuxS… 162
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 152 [OK]
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 151 [OK]
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from sou… 116 [OK]
nginxdemos/hello NGINX webserver that serves a simple page co… 83 [OK]
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 62 [OK]
nginx/nginx-ingress NGINX and NGINX Plus Ingress Controllers fo… 59
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 58
nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 35
staticfloat/nginx-certbot Opinionated setup for automatic TLS certs lo… 25 [OK]
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter for NGINX and NGIN… 23
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 … 16
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… 12
flashspys/nginx-static Super Lightweight Nginx Image 12 [OK]
mailu/nginx Mailu nginx frontend 10 [OK]
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
navidonskis/nginx-php5.6 Docker nginx + php5.6 on Ubuntu 7 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 3 [OK]
wodby/nginx Generic nginx 1 [OK]
1.2 下载Nginx镜像
docker pull nginx
1.3 查看下载好的Nginx镜像
[root@iZwz939qj61dxuoca8vryhZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest c316d5a335a5 8 days ago 142MB
centos latest 5d0da3dc9764 4 months ago 231MB
1.4 启动Nginx镜像
- -d, --detach Run container in background and print container ID
- –name string Assign a name to the container
- -p, --publish-all Publish all exposed ports to random ports
- Nginx的默认端口号是80
[root@zhouhao ~]# docker run -d --name nginx01 -p 3344:80 nginx
3702ce2af065c967ba20840a41202afcca604055bcea27bf23cb24f866b21f75
- 查看运行中的nginx容器
[root@zhouhao ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3702ce2af065 nginx "/docker-entrypoint.…" 33 seconds ago Up 32 seconds 0.0.0.0:3344->80/tcp, :::3344->80/tcp nginx01
1.5 查看Nginx的启动状况
[root@zhouhao ~]# curl localhost:3344
<!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>
1.6 进入Nginx容器
[root@zhouhao ~]# docker exec -it nginx01 /bin/bash
root@3702ce2af065:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@3702ce2af065:/# cd /etc/nginx/
root@3702ce2af065:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params
二、docker安装Tomcat
2.1 下载Tomcat
[root@zhouhao ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
0c6b8ff8c37e: Pull complete
412caad352a3: Pull complete
e6d3e61f7a50: Pull complete
461bb1d8c517: Pull complete
e442ee9d8dd9: Pull complete
542c9fe4a7ba: Pull complete
fda090e7df35: Pull complete
e5341f7d4665: Pull complete
e514be7c32d7: Pull complete
9fe0da884087: Pull complete
Digest: sha256:362db802cd2b9940bb7b4596286fdb7e6a80d334c24d297c170713778489b518
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
2.2 启动Tomcat
[root@zhouhao ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat
0d4057b8da90d41a716d81de4f249a6893e326a093628be2b366035acce22c04
2.3 进入Tomcat
[root@zhouhao ~]# docker exec -it tomcat01 /bin/bash
root@0d4057b8da90:/usr/local/tomcat# ll
bash: ll: command not found
root@0d4057b8da90:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work
发现问题
- Linux命令少了
- webapps文件夹里没有东西,所以访问不到网页。是阿里云镜像的问题,默认是最小的镜像,所以不必要的文件都剔除了,保障最小的运行环境。
2.4 停止Tomcat
[root@zhouhao ~]# docker stop 0d4057b8da90
0d4057b8da90
2.5 查看Tomcat占用的CUP资源
docker stats
Docker部署Nginx与Tomcat:容器化应用实例
本文详细介绍了如何在Docker中安装Nginx和Tomcat,包括搜索镜像、下载、启动、配置和问题解决,展示了如何通过容器化技术部署轻量级Web服务器和Java应用。
1465

被折叠的 条评论
为什么被折叠?



