Alpine Dockerfile 最佳实践
FROM openjdk:8-jre-alpine
WORKDIR /home/BHF/
COPY res.json /usr/lib/jvm/java-1.8-openjdk/jre
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
&& mkdir /var/run/nginx/ \
&& apk update \
&& apk add mysql mysql-client openrc nginx \
&& mkdir -p /run/openrc/ \
&& mkdir -p /home/BHF/ \
&& touch /run/openrc/softlevel
ENV PATH /usr/sbin:$PATH
EXPOSE 80 3306 8081
# docker run -itd --name=bhf1.0 -p 80:80 -p 3306:3306 -p 8081:8081 -p 8082:8082 -v C:/Users/Administrator/Desktop/docker/BHF/:/home/BHF/ linux/bhf:1.0 -v C:/Users/Administrator/Desktop/docker/conf.d/:/etc/nginx/conf.d/
# CMD ["java","-version"]
# docker build -f Dockerfile -t linux/bhf:1.0 .
# docker run -itd --name=bhf1.0 -p 80:80 -p 3306:3306 -p 8081:8081 -p 8082:8082 -v C:/Users/56546/Downloads/mysql/BHF/:/home/BHF/ linux/bhf:1.0
# docker rmi linux/bhf:1.0
# https://blog.csdn.net/wzfgd/article/details/114130491
进入容器后需要执行的命令
- 初始化数据库
- 配置数据库默认启动
- 启动数据库服务
- 初始化数据库密码
- 登录数据库初始化库表
- 修改数据库远程登录权限
- 开启nginx
- 开启后台服务
- 容器内编写start.sh
- 容器外服务器编写开机定时任务连接docker调用start脚本,
crontab -e
i 输入@reboot docker exec -d ContainerID sh /home/start.sh
/etc/init.d/mariadb setup
rc-update add mariadb default
rc-service mariadb start
mysqladmin -u root password '123456'
mysql -uroot -p123456
create database senser_simulation CHARACTER SET utf8 COLLATE utf8_general_ci;
use senser_simulation;
source /home/BHF/senser_simulation.sql;
cd /home/BHF/ && java -jar bhf.jar --activation=ffb7f9af01b1515fceef2c15e5a20cc6
use mysql
select User,host from mysql.user;
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
exit
vi /etc/my.cnf.d/mariadb-server.cnf
#skip-networking
#bind-address=0.0.0.0
rc-service mariadb restart
安装 apk add nginx
并配置 nginx.conf
链接
安装mysql并配置远程连接
链接
有什么不同见解可以在评论区共同讨论