Docker安装(nginx、Tomcat、es+kibana,portainer、MySql)
1.安装nginx
步骤:(1)先去https://hub.docker.com 搜索镜像
(2)下载镜像:docker pull nginx
(3)启动nginx容器
# -d 后台运行
# --name 给容器命名
# -p 宿主机端口,容器内部端口
docker run -d --name nginx01 -p 3344:80 nginx
端口暴露的概念:
2.安装Tomcat
(1)下载镜像:docker pull tomcat:9.0
(2) 启动:docker run -d -p 8089:8080 --name tomcat01 tomcat
进入容器:docker exec -it tomcat01 /bin/bash
容器内复制文件:cp -r webapps.dist/* webapps
3.部署安装es+kibana
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTIONS="-Xms64m -Xmx512m" elasticsearch:7.9.0
4.安装portainer---Docker图形化界面管理工具!提供一个后台面板供我们操作!
docker run -d -p 8088:9000 \
--restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
访问测试:外网ip:端口
5.将我们操作过的容器通过ccommit提交为一个镜像,以后我们用提交过的镜像
docker commit -a="auldlangsynezh" -m="add webapps app" 3cd14b4308d1 tomcat01:1.0
6.数据卷技术
命令:docker run -it -v /home/ceshi:/home centos /bin/bash
在本地看是否挂载上去:docker inspect 85bbfc82aacb
===》
7.docker安装MySql数据持久化到本地
首先启动数据卷父容器:docker run -it --name docker01 0d120b6ccaa8
(1)获取镜像:docker pull mysql:5.7
(2)运行容器,需要做数据挂载:docker run -d -p 3306:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:5.7
8.DockerFile
9.自己创建一个镜像:
步骤:
构建自己的centos镜像:
#1.编写dockerfile的文件
FROM centos
MAINTAINER auldlangsynezh<1441656040@qq.com>
ENV MYPATH /user/local
WORKDIR $MYPATH
RUN yum -y install vim
RUN yum -y install net-tools
EXPOSE 80
CMD echo $MYPATH
CMD echo "-----end------"
CMD /bin/bash
#2.通过这个文件构建镜像
命令:docker build -f mydockercentos -t mycentos:0.1 .
#3.测试运行
可以查看镜像本地的变更历史:docker history f0a25226b1c0
10.制作Tomcat镜像:
步骤:(1)准备镜像文件tomcat压缩包,jdk的压缩包!
(2)编写dockfile文件,命令如下:
FROM centos
MAINTAINER auldlangsynezh<1441656040@qq.com>
COPY readme.txt /user/local/readme.txt
ADD jdk-8u261-linux-x64.tar.gz /user/local/
ADD apache-tomcat-9.0.37.tar.gz /user/local/
RUN yum -y install vim
ENV MYPATH /user/local
WORKDIR $MYPATH
ENV JAVA_HOME /user/local/jdk1.8.0_261
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /user/local/apache-tomcat-9.0.37
ENV CATALINA_BASH /user/local/apache-tomcat-9.0.37
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
EXPOSE 8080
CMD /user/local/apache-tomcat-9.0.37/bin/startup.sh && tail -F /user/local/apache-tomcat-9.0.37/bin/logs/catalina.out
(2)构建镜像:
命令:docker build -t diytomcat .
(3)启动镜像:
docker run -d -p 8090:8080 --name zhtomcat -v /tomcat/webapps:/user/local/apache-tomcat-9.0.37/webapps/ -v /tomcat/tomcatlog/:/user/local/apache-tomcat-9.0.37/logs/ diytomcat:latest
11.发布自己镜像到DockerHub:
登陆:docker login -u auldlangsynezh
12.发布自己镜像到阿里云镜像服务器:
12.Docker网络:
Docker 中所有的网络接口都是虚拟的,虚拟的转发效率高!
自定义网络:
络连通:
docker network connect --help
docker network connect mynet tomcat01
12.Redis集群部署
(1)创建redis网卡:docker network create redis --subnet 172.38.0.0/16
查看网卡具体的详细信息:docker network inspect redis
(2)通过脚本创建六个redis配置
for port in $(seq 1 6);\
do \
mkdir -p /redis/node-${port}/conf
touch /redis/node-${port}/conf/redis.conf
cat << EOF >/redis/node-${port}/conf/redis.conf
port 6379
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 172.38.0.1${port}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done
(3)启动redis
启动redis-1:
docker run -p 6371:6379 -p 16371:16379 --name redis-1 \
-v /redis/node-1/data:/data \
-v /redis/node-1/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.11 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
启动redis-2:
docker run -p 6372:6379 -p 16372:16379 --name redis-2 \
-v /redis/node-2/data:/data \
-v /redis/node-2/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.12 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
启动redis-3:
docker run -p 6373:6379 -p 16373:16379 --name redis-3 \
-v /redis/node-3/data:/data \
-v /redis/node-3/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.13 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
启动redis-4:
docker run -p 6374:6379 -p 16374:16379 --name redis-4 \
-v /redis/node-4/data:/data \
-v /redis/node-4/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.14 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
启动redis-5:
docker run -p 6375:6379 -p 16375:16379 --name redis-5 \
-v /redis/node-5/data:/data \
-v /redis/node-5/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.15 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
启动redis-6:
docker run -p 6376:6379 -p 16376:16379 --name redis-6 \
-v /redis/node-6/data:/data \
-v /redis/node-6/conf/redis.conf:/etc/redis/redis.conf \
-d --net redis --ip 172.38.0.16 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf
(4)集群配置
随便进入一个:docker exec -it redis-1 /bin/sh
创建集群:redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379 172.38.0.14:6379 172.38.0.15:6379 172.38.0.16:6379 --cluster-replicas 1
查看集群信息: