- Dockerfile文件编写
Dockerfile 文件如下
FROM java:8
EXPOSE 80
ENV LANG C.UTF-8
ENV JAVA_OPTS=""
#时区
ENV TZ=Asia/Shanghai
#jar包名
ENV JAR=edu-bc-admin.jar
#工作路径
ENV WORKDIR=/opt/big-class/admin/
VOLUME /tmp
ADD $JAR $WORKDIR$JAR
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
&& echo "export LC_ALL=zh_CN.UTF-8" >> /etc/profile
WORKDIR $WORKDIR
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar $JAR"]
- 执行脚本生成镜像
docker build -t big-class/edu-bc-admin .
- 运行镜像生成容器,可以用docker run 或者 docker-compose或者其他编排工具
docker-compose.yml文件如下
version: '2'
services:
edu-bc-admin-prod:
image: big-class/edu-bc-admin
container_name: edu-bc-admin-prod
restart: always
expose:
- 80
ports:
- "8082:80"
volumes:
- /opt/big-class/admin:/opt/big-class/admin
- /opt/big-class/admin/logs:/opt/big-class/admin/logs
environment:
- spring.profiles.active=prod
- JAVA_OPTS=-Xmx512m -Xms512m
网友评论