首先創(chuàng)建tomcat的文件夾 ,為了方便docker的配置 我這里直接在根目錄中創(chuàng)建第一步:創(chuàng)建文件夾:發(fā)布文件夾
mkdir -p /docker/tomcat/webapp8081mkdir -p /docker/tomcat/webapp8082mkdir -p /docker/tomcat/webapp8083
第二步:創(chuàng)建Tomcat容器(端口 可以根據(jù)自己的實際更換)
docker run -d --name tomcat8081 -p 8081:8080 -v /docker/tomcat/webapp8081:/usr/local/tomcat/webapps/ tomcatdocker run -d --name tomcat8082 -p 8082:8080 -v /docker/tomcat/webapp8082:/usr/local/tomcat/webapps/ tomcatdocker run -d --name tomcat8083 -p 8083:8080 -v /docker/tomcat/webapp8083:/usr/local/tomcat/webapps/ tomcat
創(chuàng)建完成后使用 docker ps 命令進行查看是否創(chuàng)建成功 并且使用
第三步:查看tomcat的IP 使用命令依次查詢 這里只使用第一個舉例
docker inspect tomcat8081
第四步:為了方便測試 我這里就不上傳war包了,直接 在里面創(chuàng)建了一個hello/index.html 文件
注意:如果Nginx為Docker容器,必須使用Tomact容器IP,否則連不上
首先在官網(wǎng)上下載nginx的官方版本
官網(wǎng):http://nginx.org/en/
點擊右邊導航欄的download,進入下載界面 選擇對應的版本 進行下載,我這里就使用nginx-1.6.2.tar
下載完成后,將文件放到自定義的文件夾,我這里放到/usr/local/tools/nginx-1.6.2
使用 這個命令將nginx 解壓:
tar vxf nginx-1.6.2.tar.gz
解壓完成后,我這里是返回根目錄,在根目錄創(chuàng)建一個宿主文件夾,目的是為了創(chuàng)建文件,使得nginx可以掛載(你也可以自定義)
創(chuàng)建宿主文件夾 這里
mkdir -p /docker/nginx/vim /docker/nginx/nginx.confmkdir -p /docker/nginx/html
拷貝頁面你解壓的negix中的html文件夾中的index.html 50x.html到/docker/nginx/html文件夾中
這里提供一種negix的conf文件,以為加上注解 所以格式可能會發(fā)生改變 記得把注解刪了
Nginx.conf:
user root;
worker_processes 2; #這里設置你的線程數(shù)
#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024; #最大連接數(shù)量}http {include mime.types;default_type application/octet-stream;upstream mytomcat{server 172.17.0.3:8080 weight=10;# 另外mytomcat 這里名字和下方的名字保持一致 這里需要和你的tomcat IP保持一致server 172.17.0.4:8080 weight=50;server 172.17.0.5:8080 weight=10;}#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 logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name mytomcat;#charset koi8-r;#access_log logs/host.access.log main;location / {# root html;# index index.html index.htm;proxy_connect_timeout 50;proxy_read_timeout 10;proxy_send_timeout 20;proxy_pass http://mytomcat;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ /.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ /.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ //.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}
新聞熱點
疑難解答