当前位置:   article > 正文

Docker部署安装应用大集合(Tomcat、Nginx、Mysql、Redis、MQ、Nacos、Zookeeper、Portainer、MongoDB ......)_docker 应用中心

docker 应用中心

部署Tomcat

(1)拉取镜像

docker image pull tomcat
  • 1

(2)创建容器

 docker run -id --name tomcat666 -p 8081:8080 -v /usr/local/docker/tomcat1:/usr/local/tomcat/webapps tomcat
  • 1

(3)浏览器访问查看
在这里插入图片描述

部署Nginx

1)拉取镜像

docker pull nginx
  • 1

(2)创建Nginx容器

	docker run --name nginx-test -p 8080:80 -d nginx
  • 1

(3)浏览器查看
在这里插入图片描述
(4)对nginx部分目录进行挂载

docker run  -id -p 8080:80 --name nginx
 -v  /usr/local/docker/nginx/index:/usr/share/nginx/html 
 -v  /usr/local/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
 -v /usr/local/docker/nginx/logs:/var/log/nginx nginx
  • 1
  • 2
  • 3
  • 4

注意:在进行目录挂载时,如果不是手动创建相关目录文件时可能报错。比如nginx.conf在创建时会创建成文件夹,删除nginx.conf目录从新touch nginx.conf创建文件

部署Mysql

(1)拉取mysql镜像

docker pull mysql
  • 1

(2)创建容器

-e 代表添加环境变量 MYSQL_ROOT_PASSWORD 就是root用户的登陆密码

docker run -di --name=mysql8 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
  • 1

(3)远程登录mysql

进入容器

docker exec -it mysql8 /bin/bash
  • 1

登录MySQL

mysql -u root -p123456
  • 1

执行status查看mysql信息,以及更改刷新mysql权限

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

flush privileges;
  • 1
  • 2
  • 3

远程登陆
在这里插入图片描述
(4)对数据库某些目录作映射

docker run -di -p 3306:3306 --name mysql 
-v /usr/local/docker/mysql/conf:/etc/mysql
-v /usr/local/docker/mysql/logs:/var/log/mysql
-v/usr/local/docker/mysql/data:/var/lib/mysql -e 
MYSQL_ROOT_PASSWORD=123456  mysql
  • 1
  • 2
  • 3
  • 4
  • 5

部署Redis

(1)拉取镜像

docker pull redis
  • 1

(2)创建容器

docker run -id --name=redis666 -p 6379:6379 redis
  • 1

(3) 远程连接Redis
在这里插入图片描述

部署Redis集群

创建容器

注意:redis官网要求: docker搭建redis集群必须使用docker的主机联网模式( --net host)

docker create --name redis-node01 --net host -v redis-node01:/data redis --cluster-enabled yes --cluster-config-file nodes-node-01.conf --port 6379

docker create --name redis-node02 --net host -v redis-node02:/data redis  --cluster-enabled yes --cluster-config-file nodes-node-02.conf --port 6380

docker create --name redis-node03 --net host -v redis-node03:/data redis  --cluster-enabled yes --cluster-config-file nodes-node-03.conf --port 6381
  • 1
  • 2
  • 3
  • 4
  • 5

启动容器

 docker start redis-node01 redis-node02 redis-node03
  • 1

进入任意容器

docker exec -it  redis-node01 /bin/bash
  • 1

组建集群

注意:当遇到一直Waiting for the cluster to join,后修改组建集群IP为内外IP即可解决

root@administrator:/data# redis-cli --cluster create IP:6379 IP:6380 IP:6381 --cluster-replicas 0
>>> Performing hash slots allocation on 3 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
M: 3a14f73f21646f4e659e7f963378216912cf444a 119.23.62.62:6379
   slots:[0-5460] (5461 slots) master
M: 0087956b2d447ddc404372c33284b1e81eb4d755 119.23.62.62:6380
   slots:[5461-10922] (5462 slots) master
M: 7de5e3e07654ebdc928f96dffd029bd0f7bf45d6 119.23.62.62:6381
   slots:[10923-16383] (5461 slots) master
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
...............................................................................................................
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
root@administrator:/data# redis-cli --cluster create 172.17.0.1:6379 172.17.0.1:6380 172.17.0.1:6381 --cluster-replicas 0
>>> Performing hash slots allocation on 3 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
M: 3a14f73f21646f4e659e7f963378216912cf444a 172.17.0.1:6379
   slots
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/917773
推荐阅读
相关标签
  

闽ICP备14008679号