Docker上部署应用

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;
    #}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值