安装Docker
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
Mysql
#!/bin/bash
# 2020/04/16
# author brucelee
# Mysql Container Start Script
# 挂载目录,记得改
VLOUME_PATH=/home/docker
# 生成本地配置文件
mkdir -p $VLOUME_PATH/mysql/conf
echo '[mysqld]' > $VLOUME_PATH/mysql/conf/mysql.cnf
echo 'max_connections=1000' >> $VLOUME_PATH/mysql/conf/mysql.cnf
echo 'wait_timeout=300' >> $VLOUME_PATH/mysql/conf/mysql.cnf
# 基本设置
BASE_CNF="-d --privileged=true"
# 端口映射
PORT="-p 3306:3306"
# root账户密码
ENV="-e MYSQL_ROOT_PASSWORD=Abc123++"
#字符集
CHAR_SET="--character-set-server=utf8mb4"
# 容器名称
NAME="--name mysql"
# 开机自启动
RESTART="--restart always"
# 配置文件映射
CONF_DIR="-v $VLOUME_PATH/mysql/conf/mysql.cnf:/etc/mysql/conf.d/mysql.cnf"
# 数据文件映射
DATA_DIR="-v $VLOUME_PATH/mysql/data/:/var/lib/mysql/"
# 完整模式
docker run $BASE_CNF $PORT $ENV $NAME $RESTART $CONF_DIR $DATA_DIR mysql:latest $CHAR_SET
Java 启动
Dockerfile
FROM openjdk:20
ADD app.jar /app.jar
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
EXPOSE 8000
ENTRYPOINT ["java","-jar","/app.jar"]
启动脚本
#!/bin/bash
PORT=5000
CONTAINER_NAME=app
docker stop $CONTAINER_NAME || true
docker rm $CONTAINER_NAME || true
docker rmi $CONTAINER_NAME:latest || true
docker build -f Dockerfile -t $CONTAINER_NAME:latest .
docker run -d --name $CONTAINER_NAME -e ENV=prod -p $PORT:$PORT --restart=always $CONTAINER_NAME:latest
NginxWebUI
docker run -itd -v /home/nginxWebUI:/home/nginxWebUI -e BOOT_OPTIONS="--server.port=8080" --privileged=true --net=host --restart=always --name=nginxwebui cym1102/nginxwebui:latest
Redis
mkdir -p /home/docker/redis/config
echo "
port 6379
appendonly yes
masterauth Abc123++
requirepass Abc123++" > /home/docker/redis/config/redis.conf
docker run -d --name redis --restart=always -u root \
-p 6379:6379 \
-v /home/docker/redis/config:/etc/redis/config \
-v /home/docker/redis/data:/data \
-e TZ=Asia/Shanghai \
redis:6.2 redis-server /etc/redis/config/redis.conf
RabbitMq
mkdir -p /home/docker/rabbitmq/conf/
echo "[rabbitmq_federation_management,rabbitmq_management,rabbitmq_mqtt,rabbitmq_stomp,rabbitmq_web_stomp]." > /home/docker/rabbitmq/conf/enabled_plugins
ENV="-e RABBITMQ_ERLANG_COOKIE=rabbit_mq -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=Abc123++"
PORT="-p 15672:15672 -p 5672:5672 -p 15674:15674 -p 25672:25672 -p 4369:4369 -p 15692:15692"
VOLUMN="-v /home/docker/rabbitmq/conf/enabled_plugins:/etc/rabbitmq/enabled_plugins"
RESTART="--restart=always"
NAME="--name rabbitmq"
docker run -dit $NAME $VOLUMN $ENV $PORT $RESTART rabbitmq:latest
Minio
mkdir -p /home/docker/minio/data
# 启动Docker容器
docker run -d --restart=always\
-p 9000:9000 -p 9090:9090\
--privileged=true\
-v /home/docker/minio/data:/data/minio/data\
-e MINIO_ROOT_USER=minio\
-e MINIO_ROOT_PASSWORD=Abc123++\
--env MINIO_PROMETHEUS_AUTH_TYPE=public\
--name minio\
minio/minio:latest server /data/minio/data \
--console-address ":9090"\
--address ":9000"