docker容器: sf_nginx、sf_tomcat
sf_nginx代理转向sf_tomcat
*******************************************************************************************************************************
常用命
docker images 镜像
docker ps 启动容器
docker attach 容器Id
docker rm 删除指定容器
docker rmi 删除一个或多个image
netstat -anp | grep 8080
systemctl start tomcat
systemctl enable tomcat
1、启动新docker容器如下:
sf_ngnix 0.0.0.0:9090-->80/tcp
sf_tomcat 0.0.0.0:9080-->8080/tcp
注:宿主机与容器端口映射
2、sf_ngnix代理sf_tomcat配置如下:
1)、docker run --name=sf_ngnix --link=sf_tomcat:t01 --link=sf2_tomcat:t02 -it -p 9090:80
镜像ID /bin/bash
注:--link=sf_tomcat:t01 --link=sf2_tomcat:t02;其中t01、t02 为别名
启动新容器,–link 指定可以连接的容器,使用此参数可以让容器之间通信
2)
i) vi /etc/nginx/nginx.conf
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;
upstream tomcat_service {
#sf_tomcat:t01:8080
server t01:8080 weight=1;
#server t02:8080 weight=1;
}
include /etc/nginx/conf.d/*.conf;
}
ii) vi /etc/nginx/conf.d/default.conf
location ~ {
#nginx.conf upstream tomcat_service
proxy_pass tomcat_service;
}
iii) 启动服务 /usr/sbin/nginx
如果已经启动,可以reload /usr/sbin/nginx -s reload
4)
sf_tomcat=>http://192.168.131.131:8090
sf_nginx:sf_tomcat=>http://192.168.131.131:9090
注:http://192.168.131.131为宿主机IP
5)进入容器sf_tomcat,命systemctl不能用
解决如下:docker run --privileged -ti --name sf_tomcat 镜像ID /usr/sbin/init
参考:https://blog.csdn.net/tanzhang78/article/details/78628924 安装docker并架构nginx+tomcat容器
https://www.cnblogs.com/shadow-yin/p/10690950.html Docker 实战(二)——centos7镜像安装nginx,将安装nginx的centos容器生成新的镜像,并导出