docker安装
【centos】【docker】安装启动
docker-compose安装
【docker-compose】安装使用
配置文件
version: '2'
networks: #自定义网络myapp,为了只有这些服务可以在该网络内相互访问myapp:driver: bridge
services: #将容器抽象成服务nacos: #注册中心image: nacos/nacos-server:latestcontainer_name: nacosrestart: alwaysenvironment:MODE: standalonePREFER_HOST_MODE: ipSPRING_DATASOURCE_PLATFORM: mysqlMYSQL_SERVICE_HOST: 【ip地址】#数据库在外部MYSQL_SERVICE_PORT: 3306MYSQL_SERVICE_DB_NAME: nacos_configMYSQL_SERVICE_USER: nacosMYSQL_SERVICE_PASSWORD: Nacos@123456# MYSQL_SERVICE_DB_PARAM: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8volumes:- ./docker/nacos/standalone-logs/:/home/nacos/logsports:- "8848:8848"networks:- myappsentinel: #熔断限流image: bladex/sentinel-dashboardcontainer_name: sentinel-nacosrestart: alwaysdepends_on:- nacosenvironment:NACOS_SERVER_ADDR: nacos:8848NACOS_USERNAME: nacosNACOS_PASSWORD: nacosNACOS_NAMESPACE: publicNACOS_GROUP_ID: SENTINEL_GROUPports:- "8858:8858"networks:- myappgateway: #网关image: nacos-gatewaycontainer_name: nacos-gatewayrestart: alwaysdepends_on:- nacosports:- "18890:18890"environment:- spring.cloud.nacos.discovery.server-addr=nacos:8848- spring.cloud.sentinel.transport.dashboard=sentinel:8858networks:- myappauthserver: #认证中心image: nacos-authservercontainer_name: nacos-authserverrestart: alwaysdepends_on:- nacosenvironment:- spring.datasource.url=jdbc:mysql://10.1.58.5:3306/oauth?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=CTT- spring.cloud.nacos.discovery.server-addr=nacos:8848- spring.cloud.sentinel.transport.dashboard=sentinel:8858- JAVA_OPTS=-Dlog4j2.formatMsgNoLookups=truenetworks:- myappnacos-handheld: #业务后台接口image: nacos-handheldcontainer_name: nacos-handheldrestart: alwaysdepends_on: #gateway、authserver服务启动后本服务才启动- gateway- authserverenvironment: #springcloud项目application.yml配置修改- spring.datasource.url=jdbc:mysql://10.1.58.5:3306/handled?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=CTT- spring.profiles.active=prod- spring.cloud.nacos.discovery.server-addr=nacos:8848- security.oauth2.resource.user-info-uri=http://gateway:18890/nacos-authserver/oauth/check_token- JAVA_OPTS=-Dlog4j2.formatMsgNoLookups=truenetworks:- myapphandheld-front: #业务前端平台image: handheld-frontcontainer_name: handheld-frontrestart: alwaysdepends_on:- gateway- authserverlinks: #传递gateway服务ip地址到本容器,用于nginx反向代理配置使用gateway代替实际ip- gatewayports: #将端口暴露至宿主机的8089- "8089:80"networks:- myapp
启动docker-compose配置文件
docker-compose up -d