Docker部署Mysql+Nginx+Tomcat+Redis
Mysql部署
拉去mysql镜像
docker pull centos/mysql-57-centos7
创建mysql容器
docker run -id --name=Mymysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql
-p代表端口映射,格式为 宿主机端口:容器端口
-e代表添加环境变量 MYSQL_ROOT_PASSWORD 是root用户的登录密码
进入容器
docker exec -it Mymysql /bin/bash
登录mysql
- 本地登录
mysql -u root -p
- 远程登陆
连接宿主机的IP,指定端口为3306
Tomcat部署
拉取镜像
docker pull tomcat:7-7jre7
创建容器
docker run -id --name=mytomcat -p 8080:8080 -v /usr/local/webapps:/usr/local/tomcat/webapps tomcat:7-jre7
项目部署
将项目打包好放入容器的运行文件夹运行即可,然后根据项目访问路径访问项目。
Nginx部署
拉取镜像
docker pull nginx
创建Nginx容器
docker run -id --name=mynginx -p 80:80 nginx
Redis部署
拉取镜像
docker pull redis
创建容器
docker run -id --name=myredis -p 6379:6379 redis
附录:Nginx+Tomcat容器负载均衡配置文件
upstream tomcat_web {
server tomcatIP:8080 weight=100 max_fails=2 fail_timeout=15;
server tomcatIP:8080 weight=100 max_fails=2 fail_timeout=15;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_set_header host $host;
proxy_pass http://tomcat_web;
}
#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 /usr/share/nginx/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;
#}
}