1.在DockerToolbox安裝目錄下創(chuàng)建兩個文件夾
2.安裝docker-compose
#1
curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` > /compose
#2
chmod +x /compose
#查看版本信息
docker-compose -version
3.在test文件夾下創(chuàng)建docker-compose.yml
3.1 docker中存在鏡像
image: docker中已存在鏡像
3.2 使用build
當docker沒有springbootdemo鏡像時疲吸,可以讀取DockerFile內(nèi)容創(chuàng)建鏡像站楚,同時生產(chǎn)容器sboot01
3.3配置文件詳解:
http://www.reibang.com/p/2217cfed29d7
http://www.docker.org.cn/dockerppt/114.html
4.運行
docker-compose up
docker-compose.yml例子
redis:
image: redis:latest
ports:
- "6379:6379"
volumes:
- /mbp/redis/redis.conf:/etc/redis/redis.conf
- /mbp/redis/data:/data
command: redis-server /etc/redis/redis.conf
mysql:
image: mysql:latest
ports:
- "3306:3306"
volumes:
- /mbp/mysql/data:/data/mysql/data
- /mbp/mysql/base:/var/lib/mysql
- /mbp/mysql/mysql.cnf:/etc/mysql/my.cnf
environment:
- MYSQL_ROOT_PASSWORD=root
forecast_gaode:
build: /mbp/forecast_gaode
ports:
- "8180:9080"
volumes:
- /mbp/forecast_gaode/logs/:/mbp/reits/logs/
forecast_yuexiu:
build: /mbp/forecast_yuexiu
ports:
- "8280:9080"
volumes:
- /mbp/forecast_yuexiu/logs/:/mbp/reits/logs/
ree1:
image: ree:latest
ports:
- "8001:9068"
ree2:
image: ree:latest
ports:
- "8002:9068"
ree3:
image: ree:latest
ports:
- "8003:9068"
ree4:
image: ree:latest
ports:
- "8004:9068"
nginx_ree:
image: nginx:latest
ports:
- "8000:8000"
volumes:
- /mbp/ree/nginx.conf:/etc/nginx/nginx.conf
nginx_gaode_lan:
image: nginx:latest
ports:
- "8110:80"
volumes:
- /mbp/nginx_gaode/dist/:/etc/nginx/html/
- /mbp/nginx_gaode/nginx.conf:/etc/nginx/nginx.conf
- /mbp/nginx_gaode/serverconfig_lan.json:/etc/nginx/html/serverconfig.json
nginx_gaode_wlan:
image: nginx:latest
ports:
- "8100:80"
volumes:
- /mbp/nginx_gaode/dist/:/etc/nginx/html/
- /mbp/nginx_gaode/nginx.conf:/etc/nginx/nginx.conf
- /mbp/nginx_gaode/serverconfig_wlan.json:/etc/nginx/html/serverconfig.json
nginx_yuexiu_lan:
image: nginx:latest
ports:
- "8210:80"
volumes:
- /mbp/nginx_yuexiu/dist/:/etc/nginx/html/
- /mbp/nginx_yuexiu/nginx.conf:/etc/nginx/nginx.conf
- /mbp/nginx_yuexiu/serverconfig_lan.json:/etc/nginx/html/serverconfig.json
nginx_yuexiu_wlan:
image: nginx:latest
ports:
- "8200:80"
volumes:
- /mbp/nginx_yuexiu/dist/:/etc/nginx/html/
- /mbp/nginx_yuexiu/nginx.conf:/etc/nginx/nginx.conf
- /mbp/nginx_yuexiu/serverconfig_wlan.json:/etc/nginx/html/serverconfig.json
nginx_test1:
image: nginx:latest
ports:
- "8300:80"
volumes:
- /mbp/nginx_test1/dist/:/etc/nginx/html/
- /mbp/nginx_test1/nginx.conf:/etc/nginx/nginx.conf
nginx_test2:
image: nginx:latest
ports:
- "8400:80"
volumes:
- /mbp/nginx_test2/dist/:/etc/nginx/html/
- /mbp/nginx_test2/nginx.conf:/etc/nginx/nginx.conf
nginx_proxy:
image: nginx:latest
ports:
- "80:80"
links:
- forecast_yuexiu
volumes:
- /mbp/nginx_proxy/nginx.conf:/etc/nginx/nginx.conf
nginx_datacheck:
image: nginx:latest
ports:
- "7200:80"
volumes:
- /mbp/nginx_datacheck/dist/:/etc/nginx/html/
- /mbp/nginx_datacheck/nginx.conf:/etc/nginx/nginx.conf
nginx_demo_new_saas_front:
image: nginx:latest
ports:
- "7201:80"
volumes:
- /mbp/nginx_demo_new_saas_front/dist/:/etc/nginx/html/
- /mbp/nginx_demo_new_saas_front/nginx.conf:/etc/nginx/nginx.conf
dockerFile示例
FROM registry.cn-hangzhou.aliyuncs.com/xm123-ubuntu/sshjdk8
MAINTAINER xuming123<xuming9123@163.com>
LABEL description="默認端口為9080"
ADD reits-forecast.jar app.jar
RUN bash -c 'touch /app.jar'
#修改時區(qū)
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
#監(jiān)聽端口
EXPOSE 9080
#啟動docker自動運行jar包
ENTRYPOINT ["java","-jar","/app.jar"]