yaml
version: "3"
services:
demo:
image: dj/demo
container_name: demo
volumes:
- ./logs:/logs
environment:
TZ: Asia/Shanghai
LANG: en_US.UTF-8
JAVA_OPTS: "-Xmx512m -Xms512m"
ports:
- "8082:8081"
idea 搭建 docker
服务器端 idea 开启远程
pom.xml 修改如下
在 src 目录下 创建 docker 目录
编写 Dockerfile
FROM java:8
MAINTAINER dj dj@qq.com
COPY *.jar /app.jar
EXPOSE 8081
ENTRYPOINT ["java","-jar","app.jar"]
使用插件打包即可发布到测试环境
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<!-- 远程Docker的地址 -->
<dockerHost>http://192.168.83.133:2375</dockerHost>
<!-- 镜像名称、前缀、项目名 -->
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<!-- Dockerfile的位置 -->
<dockerDirectory>src/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<!-- 表示的target文件夹 -->
<directory>${project.build.directory}</directory>
<!-- 表示打出来的JAR包-->
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
docker 加速方案
可信镜像源 https://hub.atomgit.com/
plsql
https://hub.gog.email/
在名称前加入 地址 hub.gog.email/
docker pull hub.gog.email/apache/skywalking-oap-server:9.4.0
2
vi /etc/docker/daemon.json
添加一下内容
{"registry-mirrors": ["https://hub.gog.email"]}
systemctl daemon-reload && systemctl restart docker
https://github.com/cmliu/CF-Workers-docker.io/issues/8
docker 搭建 mysql 主从 5.7
bash
# 主
docker run -p 3306:3306 --name mysql-master \
-v /opt/docker/mysql/data:/var/lib/mysql \
-v /opt/docker/mysql/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
# 从
docker run -p 3310:3306 --name mysql-slave \
-v /opt/docker/mysql2/data:/var/lib/mysql \
-v /opt/docker/mysql2/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
# 主
docker exec -it 6259b6c58571 /bin/bash
# 进入容器 设置一个复制的账号 并授权
CREATE USER 'slave'@'*' IDENTIFIED WITH BY 'root';
CREATE USER 'slave'@'%' IDENTIFIED BY 'root';
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'*';
GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%';
flush privileges;
# 记下 pos
show master status;
#从
docker exec -it 343b6bb2bb80 /bin/bash
CHANGE MASTER TO MASTER_HOST='192.168.229.128',MASTER_PORT=3306,MASTER_USER='slave',MASTER_PASSWORD='root',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=769;
start slave;
show slave status\G;
# 在主库创建 数据库增删改查 在从库上查询记录即可
docker haproxy mysql 主从
bash
docker run -d --name haproxy -v /opt/docker/haproxy:/usr/local/etc/haproxy -p 5000:5000 haproxy:latest
# 配置文件
#----------------
# Global settings
#----------------
global
log 127.0.0.1 local2
maxconn 4000
daemon
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 500
listen mysql
bind :5000
mode tcp
balance roundrobin
option tcplog
server master 192.168.229.128:3306 check
server slave 192.168.229.128:3310 check