本文主要是介绍docker笔记5-使用docker-compose build image像并启动应用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用docker-compose build image像并启动应用
1.准备材料
website-1.0.0.jar Dockerfile docker-compose.yml
Dockerfile
FROM java:8-jre-alpine
MAINTAINER test@xx.com
ENV JAVA_OPTS null
WORKDIR /home/portal/website
ADD /home/portal/website/website-1.0.0.jar /home/portal/website/
EXPOSE 8081
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar website-1.0.0.jar" ]
VOLUME /home/portal/website:/home/portal/website
docker-compose.yml(启动单个容器)
version: '3'
services:website:build:context: .dockerfile: Dockerfileimage: website:1.0.0container_name: websiterestart: alwaysnetworks:- netsvolumes: - /home/portal/website/logs/:/home/portal/website/logs/ports:- "8081:8081"environment: - JAVA_OPTS=-Xmx256M -Dspring.profiles.active=test -Duser.timezone=GMT+08
networks: nets:external: false
2.将以上材料放到/home/portal/website目录
3.build镜像启动应用:执行docker-compose up -d
4.启动多个
docker-compose.yml
version: '3'
services:web1:build: .image: web:1.0container_name: webrestart: alwaysnetworks:- netsvolumes:- /home/portal/web/logs/:/home/portal/web/logs/ports:- "8081:8081"environment:- JAVA_OPTS=-Xmx512M -Dspring.profiles.active=test -DPWD=12345 -Duser.timezone=GMT+08web-backup:image: web:1.0container_name: web-backuprestart: alwaysnetworks:- netsvolumes:- /home/portal/web/logs/:/home/portal/web/logs/ports:- "8082:8081"environment:- JAVA_OPTS=-Xmx512M -Dspring.profiles.active=test -DPWD=12345 -Duser.timezone=GMT+08
networks:nets:external: false
这篇关于docker笔记5-使用docker-compose build image像并启动应用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!