windows本地虚拟机上运行docker-compose案例
1、先构建镜像文件dockerfile,使用docker build -t redis-demo:1.0 -f dockerfile .来构建:
FROM openjdk:8-jdk-alpineMAINTAINER qini<nq@qq.com>VOLUME /data/upload_filesWORKDIR /usr/local/nqADD ./redis-demo.jar app.jarENV profile prod
ENV timezone Asia/ShanghaiENTRYPOINT java -jar -Dspring.profiles.active=$profile -Duser.timezone=$timezone app.jar
# CMD java -jar -Dspring.profiles.active=$profile -Duser.timezone=$timezone app.jarEXPOSE 8086
2、构建成功的镜像再使用docker compose up -d 来一键启动应用:
version: "2"
services:microService:image: redis-demo:1.0container_name: redis-demoports:- "8086:8086"volumes:- /home/niqi/redis-demo-data:/datanetworks:- net_testdepends_on:- redis- mysqlredis:image: redis:latestcontainer_name: redisports:- "6379:6379"volumes:- /home/niqi/redis/redis.conf:/etc/redis/redis.conf- /home/niqi/redis/data:/datanetworks:- net_testcommand: redis-server /etc/redis/redis.confmysql:image: mysql:5.7container_name: mysqlenvironment:MYSQL_ROOT_PASSWORD: '123456'MYSQL_DATABASE: 'springboot'ports:- "3306:3306"volumes:- /home/niqi/mysql/data:/var/lib/mysql- /home/niqi/mysql/conf/my.cnf:/etc/my.cnf- /home/niqi/mysql/log:/var/lib/logrestart: alwaysnetworks:- net_testcommand: --default-authentication-plugin=mysql_native_password
networks:net_test: