Docker (III): docker deploys nginx and Tomcat

Time:2021-9-17

Life is boundless, learning is boundless

1、 Docker installation nginx

#1. Search nginx
[[email protected] home]# docker search nginx
NAME                               DESCRIPTION                                     STARS  
nginx                              Official build of Nginx.                        14539  
jwilder/nginx-proxy                Automated Nginx reverse proxy for docker con…   1981   
richarvey/nginx-php-fpm            Container running Nginx + PHP-FPM capable of…   809    
jc21/nginx-proxy-manager           Docker container for managing Nginx proxy ho…   158    
linuxserver/nginx                  An Nginx container, brought to you by LinuxS…   142    
tiangolo/nginx-rtmp                Docker image with Nginx using the nginx-rtmp…   115    
jlesage/nginx-proxy-manager        Docker container for Nginx Proxy Manager        97     
bitnami/nginx                      Bitnami nginx Docker Image                      94     
alfg/nginx-rtmp                    NGINX, nginx-rtmp-module and FFmpeg from sou…   89     
jasonrivers/nginx-rtmp             Docker images to host RTMP streams using NGI…   88     
nginxdemos/hello                   NGINX webserver that serves a simple page co…   67     
nginx/nginx-ingress                NGINX Ingress Controller for Kubernetes         49     
privatebin/nginx-fpm-alpine        PrivateBin running on an Nginx, php-fpm & Al…   48     
nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                  31     
schmunk42/nginx-redirect           A very simple container to redirect HTTP tra…   19     
staticfloat/nginx-certbot          Opinionated setup for automatic TLS certs lo…   19     
nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter                       16     
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     
flashspys/nginx-static             Super Lightweight Nginx Image                   9      
bitwarden/nginx                    The Bitwarden nginx web server acting as a r…   9      
bitnami/nginx-ingress-controller   Bitnami Docker Image for NGINX Ingress Contr…   8      
mailu/nginx                        Mailu nginx frontend                            8      
ansibleplaybookbundle/nginx-apb    An APB to deploy NGINX                          2      
wodby/nginx                        Generic nginx   

#2. Download nginx image
[[email protected] home]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a076a628af6f: Pull complete 
0732ab25fa22: Pull complete 
d7f36f6fe38f: Pull complete 
f72584a26f32: Pull complete 
7125e4df9063: Pull complete 
Digest: sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

#3. Start nginx
#- D background start
#-- name name the container
#- P host port: container port
[[email protected] home]# docker run -d  --name nginx01 -p 3344:80 nginx
0692aec62ba9f2487653629280becb8bcb915605faee12ee3bd3b8d5de148c32
[[email protected] home]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                  NAMES
0692aec62ba9   nginx     "/docker-entrypoint.…"   7 seconds ago   Up 6 seconds   0.0.0.0:3344->80/tcp   nginx01
#Try local access
[[email protected] home]# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    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>
[[email protected] home]# 

#Enter container
[[email protected] home]# docker exec -it nginx01 /bin/bash
[email protected]:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
[email protected]:/# cd /etc/nginx
[email protected]:/etc/nginx# ls
conf.d        koi-utf  mime.types  nginx.conf   uwsgi_params
fastcgi_params    koi-win  modules     scgi_params  win-utf
[email protected]:/etc/nginx# 

#Stop the operation of the container
[email protected] : / etc / nginx # exit # exit container
exit
[[email protected] home]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                  NAMES
0692aec62ba9   nginx     "/docker-entrypoint.…"   9 minutes ago   Up 9 minutes   0.0.0.0:3344->80/tcp   nginx01
[ [email protected] Home]# docker stop 0692aec62ba9 # stop container
0692aec62ba9

Use the public network to access the browser and test it. The results can also be accessed. The premise is that your 3344 port number has been developed. As long as it is the developed port number, you can test it.

Docker (III): docker deploys nginx and Tomcat

2、 Docker installing Tomcat

#Download Tomcat image
[[email protected] home]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
Digest: sha256:94cc18203335e400dbafcd0633f33c53663b1c1012a13bcad58cced9cd9d1305
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
[[email protected] home]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
tomcat       9.0       040bdb29ab37   7 weeks ago    649MB
tomcat       latest    040bdb29ab37   7 weeks ago    649MB
nginx        latest    f6d0b4767a6c   8 weeks ago    133MB
centos       latest    300e315adb2f   3 months ago   209MB
#Start the Tomcat container and map the 8080 port of the container to the 3355 port of the external network
[[email protected] home]# docker run -d -p 3355:8080 --name tomcat01 tomcat
1a0d54668dd61afb333aa0854e1c0ceafca3c8f695f820089d28eefa4977f0f6
[[email protected] home]#

Check on the browser: the result is 404, description

Docker (III): docker deploys nginx and Tomcat

#After entering the Tomcat container, you find that there is nothing under webapps. This is the reason for Alibaba cloud's image. By default, it is the smallest image. All unnecessary images are eliminated to ensure the smallest running environment
[[email protected] home]# docker exec -it tomcat01 /bin/bash
[email protected]:/usr/local/tomcat# ls -al
total 176
drwxr-xr-x 1 root root  4096 Jan 13 08:25 .
drwxr-xr-x 1 root root  4096 Jan 13 08:19 ..
-rw-r--r-- 1 root root 18982 Dec  3 11:48 BUILDING.txt
-rw-r--r-- 1 root root  5409 Dec  3 11:48 CONTRIBUTING.md
-rw-r--r-- 1 root root 57092 Dec  3 11:48 LICENSE
-rw-r--r-- 1 root root  2333 Dec  3 11:48 NOTICE
-rw-r--r-- 1 root root  3257 Dec  3 11:48 README.md
-rw-r--r-- 1 root root  6898 Dec  3 11:48 RELEASE-NOTES
-rw-r--r-- 1 root root 16507 Dec  3 11:48 RUNNING.txt
drwxr-xr-x 2 root root  4096 Jan 13 08:25 bin
drwxr-xr-x 1 root root  4096 Mar  9 11:39 conf
drwxr-xr-x 2 root root  4096 Jan 13 08:25 lib
drwxrwxrwx 1 root root  4096 Mar  9 11:39 logs
drwxr-xr-x 2 root root  4096 Jan 13 08:25 native-jni-lib
drwxrwxrwx 2 root root  4096 Jan 13 08:25 temp
drwxr-xr-x 2 root root  4096 Jan 13 08:25 webapps
drwxr-xr-x 7 root root  4096 Dec  3 11:45 webapps.dist
drwxrwxrwx 2 root root  4096 Dec  3 11:43 work
[email protected]:/usr/local/tomcat# cd webapps
[email protected]:/usr/local/tomcat/webapps# ls
[email protected]:/usr/local/tomcat/webapps# 


#Copy the files in the webapps.dist directory to webapps, and then refresh the page to see the Tomcat page
[email protected]:/usr/local/tomcat/webapps# cd ..
[email protected]:/usr/local/tomcat# cd webapps.dist
[email protected]:/usr/local/tomcat/webapps.dist# ls
ROOT  docs  examples  host-manager  manager
[email protected]:/usr/local/tomcat/webapps.dist# cd ..
[email protected]:/usr/local/tomcat# cp -r webapps.dist/* webapps
[email protected]:/usr/local/tomcat# cd webapps
[email protected]:/usr/local/tomcat/webapps# ls
ROOT  docs  examples  host-manager  manager
[email protected]:/usr/local/tomcat/webapps#

Docker (III): docker deploys nginx and Tomcat

Recommended Today

Seven Python code review tools recommended

althoughPythonLanguage is one of the most flexible development languages at present, but developers often abuse its flexibility and even violate relevant standards. So PythoncodeThe following common quality problems often occur: Some unused modules have been imported Function is missing arguments in various calls The appropriate format indentation is missing Missing appropriate spaces before and after […]