我们想创建一个开发环境,在其中可以在服务器上运行最新版本的注册表,uaa和网关。然后,我们想在本地开发和运行(在docker内部或外部)微服务。然后,应将此微服务配置为连接到另一服务器并与之通信。
我现在已经通过jhipster子生成器为我们的网关,uaa和注册表生成了一个docker-compose。然后,我尝试通过gradlew启动我当前正在使用的微服务,通过gradlew dockerBuild进行构建,并启动app.yml。我还尝试将app.yml中的主机名更改为localhost,127.0.0.1和注册表docker容器的IP。
docker-compose.yml(注册表,UAA和网关)
version: '2'
services:
mygateway-app:
image: mygateway
environment:
- SPRING_PROFILES_ACTIVE=prod,swagger
- EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/eureka
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/config
- SPRING_DATASOURCE_URL=jdbc:mysql://mygateway-mysql:3306/mygateway?useUnicode=true&characterEncoding=utf8&useSSL=false
- JHIPSTER_SLEEP=30
- JHIPSTER_REGISTRY_PASSWORD=admin
ports:
- 8080:8080
depends_on:
- "mygateway-mysql"
- "myuaa-app"
mygateway-mysql:
image: mysql:5.7.20
environment:
- MYSQL_USER=root
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=mygateway
command: mysqld --lower_case_table_names=1 --skip-ssl
--character_set_server=utf8mb4 --explicit_defaults_for_timestamp
myuaa-app:
image: myuaa
environment:
- SPRING_PROFILES_ACTIVE=prod,swagger
- EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/eureka
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}@jhipster-registry:8761/config
- SPRING_DATASOURCE_URL=jdbc:mysql://myuaa-mysql:3306/myuaa?useUnicode=true&characterEncoding=utf8&useSSL=false
- JHIPSTER_SLEEP=30
- JHIPSTER_REGISTRY_PASSWORD=admin
depends_on:
- "myuaa-mysql"
- "jhipster-registry"
myuaa-mysql:
image: mysql:5.7.20
environment:
- MYSQL_USER=root
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_DATABASE=myuaa
command: mysqld --lower_case_table_names=1 --skip-ssl
--character_set_server=utf8mb4 --explicit_defaults_for_timestamp
jhipster-registry:
extends:
file: jhipster-registry.yml
service: jhipster-registry
app.yml(微服务)
version: '2'
services:
myservice-app:
image: myservice
environment:
# - _JAVA_OPTIONS=-Xmx512m -Xms256m
- SPRING_PROFILES_ACTIVE=prod,swagger
- EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}@localhost:8761/eureka
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}@localhost:8761/config
- SPRING_DATASOURCE_URL=jdbc:mysql://myservice-mysql:3306/myservice?useUnicode=true&characterEncoding=utf8&useSSL=false
- JHIPSTER_SLEEP=10 # gives time for the JHipster Registry to boot before the application
- JHIPSTER_REGISTRY_PASSWORD=admin
myservice-mysql:
extends:
file: mysql.yml
service: myservice-mysql
# jhipster-registry:
# extends:
# file: jhipster-registry.yml
# service: jhipster-registry
# environment:
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=native
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_LOCATIONS=file:./central-config/docker-config/