创建镜像
1. 安装资源地址
http://dl.mycat.org.cn/2.0/
2. Dockerfile文件
FROM openjdk:8-jre
ENV AUTO_RUN_DIR ./mycat2
ENV DEPENDENCE_FILE mycat2-1.22-release-jar-with-dependencies.jar
ENV TEMPLATE_FILE mycat2-install-template-1.21.zip
RUN sed -i "s@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list
RUN sed -i "s@http://.*security.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list
RUN buildDeps='procps wget unzip' \
&& apt-get update \
&& apt-get install -y $buildDeps
# 安装地址 http://dl.mycat.org.cn/2.0/
# http://dl.mycat.org.cn/2.0/1.22-release/
# http://dl.mycat.org.cn/2.0/install-template/
RUN wget -P $AUTO_RUN_DIR/ http://dl.mycat.org.cn/2.0/1.22-release/$DEPENDENCE_FILE \
&& wget -P $AUTO_RUN_DIR/ http://dl.mycat.org.cn/2.0/install-template/$TEMPLATE_FILE
RUN cd $AUTO_RUN_DIR/ \
&& unzip $TEMPLATE_FILE \
&& ls -al . \
&& mv $DEPENDENCE_FILE mycat/lib/ \
&& chmod +x mycat/bin/* \
&& chmod 755 mycat/lib/* \
&& mv mycat /usr/local
#copy mycat /usr/local/mycat/
VOLUME /usr/local/mycat/conf
VOLUME /usr/local/mycat/logs
EXPOSE 8066 1984
CMD ["/usr/local/mycat/bin/mycat", "console"]
3. 编译镜像
docker build -t mycat2:1.22 .
创建容器
1. 复制配置
docker run -d --name=mycat2 -p 8066:8066 -p 1984:1984 mycat2:1.22
# 复制容器内配置
docker cp mycat2:/usr/local/mycat/conf .
docker cp mycat2:/usr/local/mycat/logs .
2. 创建容器
docker run -d --name=mycat2 -p 8066:8066 -p 1984:1984 -v $PWD/conf:/usr/local/mycat/conf -v $PWD/logs:/usr/local/mycat/logs mycat2:1.22
# 以root用户权限进入容器
docker exec -it -u root mycat2 bash
# 查看容器启动日志
docker logs -f mycat2
3. docker-compose方式安装
version: '3'
services:
mycat-service:
build:
context: ./mycat/
dockerfile: Dockerfile
image: mycat2:1.22
container_name: mycat2
restart: always
network_mode: "host"
volumes:
- /u01/mycat2/conf:/usr/local/mycat/conf
- /u01/mycat2/logs:/usr/local/mycat/logs