docker部署常见环境
- 容器 --->>> 宿主机
docker cp mysql:容器内目录地址 宿主机目录地址
- 宿主机 --->>> 容器
docker cp 宿主机目录地址 mysql:容器内目录地址
- Portainer容器可视化管理
- SimpleDocker【目前还不好用】
- MySql环境
- redis环境
- 阿里巴巴流量卫兵sentinel-dashboard
- Tomcat
- Nacos
- Apollo
- Nginx
- NginxWebUI
- 基于docker 搭建Prometheus+Grafana
- ElasticView工具
- Minio文件服务
- Zookeeper协调服务
- easydarwin流媒体服务器
- shenyu(神禹网关)
- YAPI接口管理工具
- java-spring项目部署容器
- 更多服务部署参考
容器 --->>> 宿主机 docker cp mysql:容器内目录地址 宿主机目录地址
宿主机 --->>> 容器 docker cp 宿主机目录地址 mysql:容器内目录地址
注意
1、选择合适的数据挂载位置:一般选取容量大的硬盘块:
df -h
2、docker容器 与 宿主机 时钟不一致问题,添加环境变量 [-e "TZ=Asia/Shanghai"]
Portainer容器可视化管理
容器构建命令:
# 上传中文包到/data/docker_data_volume_list/portainer_web/public路径下
$ docker search portainer
$ docker pull portainer:latest
$ docker run -d -p 9000:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v /data/docker_data_volume_list/portainer_data:/data -v /data/docker_data_volume_list/portainer_web/public:/public --name prtainer-test portainer/portainer
SimpleDocker【目前还不好用】
https://gitee.com/taoes_admin/SimpleDocker
MySql环境
账号密码:root/root
容器构建命令:
$ docker search mysql
$ docker pull mysql:8.0.19
$ docker run \
-d \
-p 3306:3306 \
--restart=always \
--name mysql \
-v /data/docker_data_volume_list/mysql/log:/var/log/mysql \
-v /data/docker_data_volume_list/mysql/data:/var/lib/mysql \
-v /data/docker_data_volume_list/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
mysql:8.0.19
redis环境
密码:zlHjV0tdO5yNYMhbrCfJE1ZA6I2na
$ docker search redis
$ docker pull redis:latest
$ docker run \
-d \
--name redis-test \
-p 6379:6379 \
--restart=always \
-v /data/docker_data_volume_list/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /data/docker_data_volume_list/redis/conf/data:/data \
redis \
--requirepass "zlHjV0tdO5yNYMhbrCfJE1ZA6I2naR"
阿里巴巴流量卫兵sentinel-dashboard
地址:http://ip:8858
sentinel/sentinel
容器构建命令:
$ docker search sentinel-dashboard
$ docker pull bladex/sentinel-dashboard
$ docker run \
-d \
-p 8858:8858 \
--name sentinel-test \
--restart=always \
bladex/sentinel-dashboard:latest
Tomcat
$ docker pull tomcat:jre11-openjdk-slim-buster
$ docker run \
--rm/--restart=always \ # 二选一
-d \
-p 8080:8080 \
--name test \
-v /home/docker_volume_list/tomcat_volume/war_dir:/usr/local/tomcat/webapps \
-v /home/docker_volume_list/tomcat_volume/log_dir:/usr/local/tomcat/logs \
tomcat:jre11-openjdk-slim-buster
Nacos
部署时注意版本问题,并且开放心跳监测的端口7848、8848、9848
数据库先建表:https://github.com/alibaba/nacos/blob/develop/distribution/conf/nacos-mysql.sql
$ docker search nacos/nacos-server
$ docker pull nacos/nacos-server
$ docker run \
--rm/--restart=always \
-d \
--name nacosByJHL \
# -p 7848:7848 \
# -p 8848:8848 \
# -p 9848:9848 \
--network host \
-e MODE=standalone \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=192.168.8.8 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=woaini \
nacos/nacos-server
https://hub.docker.com/r/nacos/nacos-server
访问地址:http://ip:8848/nacos
nacos/nacos
报错信息
/usr/local/jdk-11.0.8/bin/java -server -Xms2g -Xmx2g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m -XX:-OmitStackTraceInFastThrow -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/docker_data_volume_list/nacos_test_app/nacos-server-1.3.1/nacos/logs/java_heapdump.hprof -XX:-UseLargePages -Dnacos.member.list= -Xlog:gc*:file=/data/docker_data_volume_list/nacos_test_app/nacos-server-1.3.1/nacos/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400 -Dloader.path=/data/docker_data_volume_list/nacos_test_app/nacos-server-1.3.1/nacos/plugins/health,/data/docker_data_volume_list/nacos_test_app/nacos-server-1.3.1/nacos/plugins/cmdb -Dnacos.home=/data/docker_data_volume_list/nacos_test_app/nacos-server-1.3.1/nacos -jar /data/docker_data_volume_list/nacos_test_app/nacos-server-1.3.1/nacos/target/nacos-server.jar --spring.config.location=classpath:/,classpath:/config/,file:./,file:./config/,file:/data/docker_data_volume_list/nacos_test_app/nacos-server-1.3.1/nacos/conf/ --logging.config=/data/docker_data_volume_list/nacos_test_app/nacos-server-1.3.1/nacos/conf/nacos-logback.xml --server.max-http-header-size=524288
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000080000000, 2147483648, 0) failed; error='Not enough space' (errno=12)# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2147483648 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /data/docker_data_volume_list/nacos_test_app/nacos-server-1.3.1/nacos/bin/hs_err_pid4305.log
内存不足问题解决,查看内存:free -h
Apollo
docker部署文档地址
1.先起一个临时容器,将启动脚本复制出来
2.新建数据库表(docker部署文档地址中自取)
3.更改数据库连接配置
# apollo config db info
apollo_config_db_url="jdbc:mysql://192.168.8.8:3306/ApolloConfigDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_config_db_username=root
apollo_config_db_password=woaini
# apollo portal db info
apollo_portal_db_url="jdbc:mysql://192.168.8.8:3306/ApolloPortalDB?characterEncoding=utf8&serverTimezone=Asia/Shanghai"
apollo_portal_db_username=root
apollo_portal_db_password=woaini
4.注意:一定要以主机模式启动
,不然apollo自己的eureka服务协调中心无法正常协调apollo的各个服务(主要指config service、admin service、Portal service之间的协调)
$ docker pull nobodyiam/apollo-quick-start
$ docker run \
--rm/--restart=always \
--name apolloByJHL \
--network host \
-v /docker_volume/demo.sh:/apollo-quick-start/demo.sh \
nobodyiam/apollo-quick-start \
bash -c "/apollo-quick-start/demo.sh start && tail -f /dev/null"
报错:WARNING: Published ports are discarded when using host network mode
原因:
docker启动时指定--network=host或-net=host,如果还指定了-p或-P,那这个时候就会有此警告,并且通过-p或-P设置的参数将不会起到任何作用,端口号会以主机端口号为主,重复时则递增。
解决:
解决的办法就是不指定-p参数,或者使用docker的其他网络模式,例如--network=bridge,这样就可以解决问题
eureka地址:http://ip:8080
admin地址:http://ip:8090
Apollo UI 界面:http://ip:8070/
apollo/admin
Nginx
- 1.找到合理的数据挂载点
查容量df -h
挂载到容量最大的目录
- 2.创建目录
mkdir -p /最大容量挂载点/docker_data_volume_list/nginx/conf.d
mkdir -p /最大容量挂载点/docker_data_volume_list/nginx/html
mkdir -p /最大容量挂载点/docker_data_volume_list/nginx/log
- 3.挂载映射
vim /最大容量挂载点/docker_data_volume_list/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
vim /最大容量挂载点/docker_data_volume_list/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
vim /最大容量挂载点/docker_data_volume_list/nginx/html/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
- 部署脚本
$ docker search nginx
$ docker pull docker.io/nginx
$ docker run \
-d \
--name nginx-test \
--rm \
-p 9111:80 \
# 映射容器内nginx默认配置文件目录
-v /最大容量挂载点/docker_data_volume_list/nginx/conf.d:/etc/nginx/conf.d \
# 映射主配置文件
-v /最大容量挂载点/docker_data_volume_list/nginx/nginx.conf:/etc/nginx/nginx.conf \
# 映射日志文件
-v /最大容量挂载点/docker_data_volume_list/nginx/log:/var/log/nginx \
# 映射静态文件
-v /最大容量挂载点/docker_data_volume_list/nginx/html:/usr/share/nginx/html \
docker.io/nginx
shell脚本部署nginx
touch nginx_start && chmod 777 nginx_start && vim nginx_start
#!/bin/bash
set -eu
mkdir -p /docker_data_volume_list/nginx/conf.d&& mkdir -p /docker_data_volume_list/nginx/html&&mkdir -p /docker_data_volume_list/nginx/log
echo "server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}" > /docker_data_volume_list/nginx/conf.d/default.conf
echo "user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}" > /docker_data_volume_list/nginx/nginx.conf
echo "<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>" > /docker_data_volume_list/nginx/html/index.html
docker run -d --rm -p 9111:80 -v /docker_data_volume_list/nginx/conf.d:/etc/nginx/conf.d -v /docker_data_volume_list/nginx/nginx.conf:/etc/nginx/nginx.conf -v /docker_data_volume_list/nginx/log:/var/log/nginx -v /docker_data_volume_list/nginx/html:/usr/share/nginx/html docker.io/nginx
NginxWebUI
https://gitee.com/cym1102/nginxWebUI#docker安装说明
docker pull cym1102/nginxwebui:latest
docker run -d --name nginxManage --restart=always \
-v /数据文件挂载目录/nginxWebUI:/home/nginxWebUI \
-e BOOT_OPTIONS="--server.port=8080" \
--privileged=true \
--net=host \
cym1102/nginxwebui:latest
基于docker 搭建Prometheus+Grafana
https://www.cnblogs.com/xiao987334176/p/9930517.html
docker版
本地安装版
监控仪表盘官方模板库
Grafana密码重置:建议直接修改SQLITE3中的admin数据
ElasticView工具
docker run --restart=unless-stopped -d -p 8090:8090 -v /data/elastic_view/data:/data -v /data/elastic_view/logs:/logs kecikeci/elastic_view:latest
Minio文件服务
# 创建数据挂载点
docker pull quay.io/minio/minio
mkdir -p /minio/data
docker run \
-p 9000:9000 \
-p 9001:9001 \
--name minio \
-d \
--restart=always \
-v /docker_data_volume_list/minio/data:/data \
-e "MINIO_ROOT_USER=admin" \
-e "MINIO_ROOT_PASSWORD=admin" \
quay.io/minio/minio server /data --console-address ":9001"
设置数据桶的访问权限,不然只能上传无法访问
码云代码仓库有文件工具:https://gitee.com/bdj/SpringBoot_v2.git
使用亚马逊的sdk,aws-s3 通用存储操作 支持所有兼容s3协议的云存储: {阿里云OSS,腾讯云COS,七牛云,京东云,minio 等}
<!-- 亚马逊aws-s3 -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws-java-sdk-s3.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
Zookeeper协调服务
单节点部署
docker run --name zk-server --restart always -d -p 2181:2181 -p 2888:2888 -p 3888:3888 -p 8080:8080 zookeeper
集群部署(使用docker-compose)
version: '3.1'
services:
zoo1:
image: zookeeper
restart: always
hostname: zoo1
ports:
- 2181:2181
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo2:
image: zookeeper
restart: always
hostname: zoo2
ports:
- 2182:2181
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
zoo3:
image: zookeeper
restart: always
hostname: zoo3
ports:
- 2183:2181
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
easydarwin流媒体服务器
https://hub.docker.com/r/justtin/easydarwin
docker run --rm --name easydarwin -p 554:554 -p 10008:10008 -d justtin/easydarwin:latest
shenyu(神禹网关)
快速开始
1、安装网关行为管理端
# 默认监听主机9095端口
$ docker pull apache/shenyu-admin&&docker run -d --rm --network host apache/shenyu-admin
2、安装网关(真正起网关作用的服务)
# 默认监听主机9195端口
$ docker pull apache/shenyu-bootstrap&&docker run -d --rm --network apache/shenyu-bootstrap
3、访问管理端:http://ip:9095
默认令牌:admin/123456
YAPI接口管理工具
注意:必须使用谷歌浏览器,并且要安装跨域请求插件:https://juejin.cn/post/6844904057707085832
github
dockerHub
# 1.创建网络
docker network create yapi
# 2.部署mongo
docker pull mongo:latest
docker volume create mongo-data
docker run -d --name mongodb --restart always --network yapi -p 27017:27017 -v mongo-data:/data/db -e MONGO_INITDB_DATABASE=yapi -e MONGO_INITDB_ROOT_USERNAME=yapipro -e MONGO_INITDB_ROOT_PASSWORD=yapipro1024 mongo:latest
# 3.初始化mongo数据
docker exec -it mongodb /bin/sh
mongo localhost:27017
use admin;
db.auth("yapipro", "yapipro1024");
use yapi;
db.createUser({user: 'yapi',pwd: 'yapi123456',roles: [{ role: "dbAdmin", db: "yapi" },{ role: "readWrite", db: "yapi" }]});
# 4.退出
exit
exit
# 5.创建yapi配置文件
vim config.json
{"port":"3000","adminAccount":"hexiaohei1024@gmail.com","timeout":120000,"db":{"servername":"mongo","DATABASE":"yapi","port":27017,"user":"yapi","pass":"yapi123456","authSource":""},"mail":{"enable":true,"host":"smtp.gmail.com","port":465,"from":"*","auth":{"user":"hexiaohei1024@gmail.com","pass":"xxx"}}}
# 6.yapi数据初始化服务
docker pull yapipro/yapi:latest
docker run -d --rm --name yapi-init --link mongodb:mongo --network yapi -v $PWD/config.json:/yapi/config.json yapipro/yapi:latest server/install.js
# 7、部署yapi
docker run -d --name yapi --link mongodb:mongo --restart always --network yapi -p 3000:3000 -v $PWD/config.json:/yapi/config.json yapipro/yapi:latest server/app.js
# 8.验证
curl localhost:3000
http://ip:3000
java-spring项目部署容器
# vim Dockerfile
# 镜像构建命令
# docker build -t 镜像名称[:tag] .
# 容器启动命令
# docker run -d --restart always --name 容器名称 -p 8080:8000 -v /data/docker_data_volume_list/jar包文件夹:/jar 镜像名称[:tag]
FROM openjdk:11
MAINTAINER 295672923@qq.com
RUN mkdir -p /jar
WORKDIR /jar
ENV TZ Asia/Shanghai
VOLUME ["/jar"]
EXPOSE 8080
ENTRYPOINT ["java","-jar","后端代码.jar"]