docker快速搭建日常应用
原创
©著作权归作者所有:来自51CTO博客作者rundreamsFly的原创作品,请联系作者获取转载授权,否则将追究法律责任
基础环境准备
基础信息
- docker通讯底层基于iptables,firewalld也是对iptables的封装
- docker-compose是单击容器编排工具
- docker-swarm跨机器进行容器编排,docker内置
- kubernetes 用于大量容器编排工具
docker安装
docker快速构建应用
mysql
docker run -p 3306:3306 --name mysql -v /home/docker/mysql/conf:/etc/mysql -v /home/docker/mysql/logs:/logs -v /home/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=12ncqOwTCGyg7tYbr34 -d mysql:5.7
- 映射外网端口:3306
- 容器名字: mysql
- 宿主机持久化、日志、配置文件目录:/home/docker
- 版本: 5.7
- 默认的root密码: 12ncqOwTCGyg7tYbr34
postgre
docker run -p 5432:5432 -v /home/docker/postgresql/data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=123456 -e TZ=PRC --name=postgres postgres
- 映射外网端口:5432
- 容器名字: postgres
- 宿主机持久化目录:/home/docker/postgresql/data
- 默认的root密码: 123456
nacos
docker run --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server
- 映射外网端口:8848
- 容器名字: nacos
- 模式为单机启动:MODE
gogs
docker run -d -p 10022:22 -p 10080:3000 --name=gogs -v /home/gogs/data/:/data gogs/gogs
- 映射外网端口:10080
- 容器名字: nacos
- 模式为单机启动:MODE
sentinel
docker run --name sentinel -d -p 8858:8858 -d bladex/sentinel-dashboard
- 映射外网端口:8858
- 容器名字: sentinel
zipkin
docker run -d --restart always -p 9411:9411 --name zipkin openzipkin/zipkin
jenkins
docker run -d \
--restart always \
--name jenkins \
-u root \
-p 5892:8080 \
-v /home/docker/jenkins/jenkins-data:/var/jenkins_home \
-v /home/docker/jenkins/docker.sock:/var/run/docker.sock \
-v /home/docker/jenkins:/home \
- 映射外网端口:5892
- 容器名字: jenkins
- 宿主机持久化目录:/home/docker/jenkins
nginx
docker run -d -p 8100:80 \
--name nginx \
-v /home/nginx/html:/usr/share/nginx/html \
-v /home/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx/logs:/var/log/nginx \
-v /home/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf \
--privileged=true \
- 映射外网端口:8100
- 容器名字: nginx
- 宿主机持久化目录:/home/nginx
rancher
docker run -d -v /home/docker/rancher/mysql-data/mysql:/var/lib/mysql --restart=unless-stopped -p 5652:8080 rancher/server
redis
docker run -p 6379:6379 --name redis -v /home/redis/redis.conf:/etc/redis/redis.conf -v /home/redis/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes --requirepass 123456
- 映射外网端口:6379
- 容器名字: redis
- 宿主机持久化目录:/home/redis
- redis密码:123456
portainer
docker run -d -p 9000:9000 \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
- 映射外网端口:9000
- 容器名字: portainer
rocketMQ
nameServer
docker run -d \
--name rmqnamesrv \
-p 19876:9876 \
-v /home/docker/rocketmq/data/namesrv/logs:/root/logs \
-v /home/docker/rocketmq/data/namesrv/store:/root/store \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms1024m -Xmx1024m" \
rocketmqinc/rocketmq sh
- 映射外网端口:19876
- 容器名字: rmqnamesrv
- 宿主机持久化目录:/home/docker/rocketmq/data
broker服务器
docker run -d \
--name rmqbroker \
-v /home/docker/rocketmq/data/broker/logs:/root/logs \
-v /home/docker/rocketmq/data/broker/store:/root/store \
-v /home/docker/rocketmq/data/conf/broker.conf:/opt/rocketmq/conf/broker.conf \
--link rmqnamesrv:namesrv -e "NAMESRV_ADDR=IP:19876" \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms1024m -Xmx1024m" \
rocketmqinc/rocketmq sh
- 映射外网端口:10911
- 容器名字: rmqbroker
- 宿主机持久化目录:/home/docker/rocketmq/data/broker
- NAMESRV_ADDR=IP:19876当前的rmqnamesrv IP及端口
界面控制台
docker run -d \
-e "JAVA_OPTS=-Drocketmq.config.namesrvAddr=IP:19876 -Drocketmq.config.isVIPChannel=false" \
-p 9993:8080 -t styletang/rocketmq-console-ng
- 映射外网端口:9993
- namesrvAddr=IP:19876当前的rmqnamesrv IP及端口
rocketMQ docker-compose启动
version: '3.5'
services:
rmqnamesrv:
image: rocketmqinc/rocketmq-namesrv
container_name: rmqnamesrv
ports:
- 19876:9876
volumes:
- /home/docker/rocketmq/namesrv/logs:/opt/logs
- /home/docker/rocketmq/namesrv/store:/opt/store
rmqbroker:
image: rocketmqinc/rocketmq-broker
container_name: rmqbroker
ports:
- 10909:10909
- 10911:10911
volumes:
- /home/docker/rocketmq/broker/logs:/opt/logs
- /home/docker/rocketmq/broker/store:/opt/store
- /home/docker/rocketmq/broker/broker.conf:/etc/rocketmq/broker.conf
environment:
NAMESRV_ADDR: "192.168.0.37:19876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: mqbroker -c /home/docker/rocketmq/broker/broker.conf
depends_on:
- rmqnamesrv
rmqconsole:
image: styletang/rocketmq-console-ng
container_name: rmqconsole
ports:
- 7799:8080
environment:
JAVA_OPTS: "-Drocketmq.namesrv.addr=192.168.0.37:19876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
xxl-job
docker run -d \
-e PARAMS="--spring.datasource.url=jdbc:mysql://192.168.0.37:3307/xxl_job?Unicode=true&characterEncoding=UTF-8 --spring.datasource.username=root --spring.datasource.password=123456 --xxl.job.accessToken=a984ddf0-ce9d-40a2-84d3-3ffba0d21ee0" \
-e JAVA_OPTS="-Xms512m -Xmx512m" \
-p 7777:8080 \
-v /home/docker/xxllog:/data/applogs \
- 映射外网端口:7777
- 容器名字: xxl-job-admin
- 宿主机持久化目录:/home/docker/rocketmq/data/broker
- -e PARAMS 配置JDBC信息
netdata
docker run -d --name=netdata \
-p 19999:19999 \
-v /home/docker/netdata/netdataconfig:/etc/netdata \
-v /home/docker/netdata/netdatalib:/var/lib/netdata \
-v /home/docker/netdata/netdatacache:/var/cache/netdata \
-v /home/docker/netdata/etc/passwd:/host/etc/passwd:ro \
-v /home/docker/netdata/etc/group:/host/etc/group:ro \
-v /home/docker/netdata/proc:/host/proc:ro \
-v /home/docker/netdata/sys:/host/sys:ro \
-v /home/docker/netdata/etc/os-release:/host/etc/os-release:ro \
--restart unless-stopped \
--cap-add SYS_PTRACE \
--security-opt apparmor=unconfined \