docker与swarm和spring boot组合,无法连接到不同节点上的数据库

时间:2016-06-01 18:03:55

标签: docker spring-boot docker-compose docker-machine docker-swarm

这是我的module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine'], files: [ // Polyfills. 'node_modules/es6-shim/es6-shim.js', 'node_modules/reflect-metadata/Reflect.js', // System.js for module loading 'node_modules/systemjs/dist/system-polyfills.js', 'node_modules/systemjs/dist/system.src.js', // Zone.js dependencies 'node_modules/zone.js/dist/zone.js', 'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/async-test.js', 'node_modules/zone.js/dist/fake-async-test.js', // RxJs. { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false }, // { pattern: 'node_modules/ng2-translate/**/*.js', included: false, watched: false}, {pattern: 'karma-test-shim.js', included: true, watched: true}, {pattern: 'dist/app/matchers.js', included: true, watched: true}, // paths loaded via module imports // Angular itself // {pattern: 'node_modules/@angular/router-deprecated/index.js', included: false, watched: true}, {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false}, // {pattern: 'node_modules/@angular2-material/**/*.js', included: false, watched: true}, {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false}, // Our built application code {pattern: 'dist/app/**/*.js', included: false, watched: false}, // paths loaded via Angular's component compiler // (these paths need to be rewritten, see proxies section) {pattern: 'dist/**/*.html', included: false, watched: false}, {pattern: 'dist/**/*.css', included: false, watched: false}, {pattern: 'dist/assets/images/**/*.jpg', watched: false, included: false, served: true}, {pattern: 'dist/assets/images/**/*.png', watched: false, included: false, served: true}, {pattern: 'dist/assets/i18n/**/*.json', watched: false, included: false, served: true}, // {pattern: 'dist/local_config.json', watched: false, included: false, served: true}, {pattern: 'node_modules/ng2-translate/**/*.js', watched: false, included: false, served: true}, // paths to support debugging with source maps in dev tools {pattern: 'src/**/*.ts', included: false, watched: false}, {pattern: 'dist/**/*.js.map', included: false, watched: false} ], // proxied base paths proxies: { // required for component assests fetched by Angular's compiler "/app/": "/base/dist/app/", "/assets/": "/base/dist/assets/", "/i18n/": "/base/dist/assets/i18n/", "//": "/base/dist/" }, // list of files to exclude exclude: [ 'node_modules/@angular/**/*spec.js' ], // // preprocess matching files before serving them to the browser // // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { 'app/**/!(*spec).js': ['coverage'] }, meta: { 'app/**/*.js': { format: 'register' } }, reporters: ['progress', 'coverage'], coverageReporter: { dir: 'coverage/', reporters: [ { type: 'text-summary' }, { type: 'json', subdir: '.', file: 'coverage-final.json' }, { type: 'html' } ], instrumenterOptions: { istanbul: { noCompact: true } } }, // coverageReporter : { // type: 'html', // dir: 'coverage/' // }, port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false }) } 文件:

docker-compose.yml

这是数据源version: '2' services: app: image: pedramrn/webapp:0.1.4 expose: - 8080 networks: - main working_dir: /src restart: never depends_on: - db-postgresql links: - db-postgresql lb: image: dockercloud/haproxy:1.5 depends_on: - app volumes: - /var/run/docker.sock:/var/run/docker.sock ports: - 80:80 networks: - main environment: - ADDITIONAL_SERVICES=springbootdockertemplate:app db-postgresql: image: postgres:9.5 ports: - "5432:5432" volumes: - data-postgresql:/var/lib/postgresql/data networks: - main restart: unless-stopped environment: - POSTGRES_USER=user - POSTGRES_PASSWORD=pass - POSTGRES_DB=postgres volumes: data-postgresql: networks: main:

如果我删除了url: jdbc:postgresql://db-postgresql:5432/postgres spring引导无法连接到postgres数据库,虽然它在单个节点上没有links: db-postgresql但在不同节点上的每个容器都没有。

在docker documentation上,使用新的多主机网络功能,容器可以使用其名称进行解析。

注意:我已根据文档与领事建立了密钥库。

links

0 个答案:

没有答案