将docker-compose升级到版本3

这是我的docker-compose.yml文件的样子。 正如你所看到的,有一个nginx服务器,一个mongoDB,主要应用程序和testing夜间和selenium容器。

nginx: container_name: 'nginx' image: 'nginx:1.11' restart: 'always' ports: - '80:80' - '443:443' volumes: - '/opt/nginx/conf.d:/etc/nginx/conf.d:ro' - '/opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro' - '/etc/letsencrypt:/etc/letsencrypt' - '/opt/nginx/www:/var/www:ro' links: - 'app' nightwatch: container_name: nightwatch image: 'registry.example.com/project/core:nightwatch' links: - selenium stdin_open: true tty: true selenium: container_name: selenium image: selenium/standalone-chrome ports: - 4444:4444 links: - app db: container_name: db image: 'mongo:3.4' restart: 'always' volumes: - '/opt/mongo/project/prod:/data/db' app: container_name: app image: 'registry.example.de/project/core:latest' restart: always links: - 'db' environment: - ROOT_URL=https://example.com - MONGO_URL=mongodb://db/db 

你也可以看到,我仍然在使用版本1,我想升级到当前版本(3)。 还有一些转换文件的问题。

例如,我不明白应该使用network选项,而不是废弃的link来访问容器。

nightwatch容器,我正在运行一个脚本

 module.exports = { 'start application': function(browser) { browser .url('http://app') // <-- .waitForElementVisible('body', 10000) .getTitle(function(result) { this.assert.equal(typeof result, 'string') }) }, } 

所以我需要通过nightwatch使用app容器,这也需要selenium 。 主要的app当然需要db

我需要一些帮助转换到版本3:

 version: '3' services: nginx: ... nightwatch: ... 

这应该够了:

 version: "3" services: nginx: container_name: 'nginx' image: 'nginx:1.11' restart: 'always' ports: - '80:80' - '443:443' volumes: - '/opt/nginx/conf.d:/etc/nginx/conf.d:ro' - '/opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro' - '/etc/letsencrypt:/etc/letsencrypt' - '/opt/nginx/www:/var/www:ro' links: - app nightwatch: container_name: nightwatch image: 'registry.example.com/project/core:nightwatch' links: - selenium stdin_open: true tty: true selenium: container_name: selenium image: selenium/standalone-chrome ports: - 4444:4444 links: - app db: container_name: db image: 'mongo:3.4' restart: 'always' volumes: - '/opt/mongo/project/prod:/data/db' app: container_name: app image: 'registry.example.de/project/core:latest' restart: always links: - db environment: - ROOT_URL=https://example.com - MONGO_URL=mongodb://db/db 

您不需要configuration额外的networking,而不是通过撰写提供的默认networking。

链接容器仍然如此configuration。 尝试这个:

 version: "3" services: abc: image: ubuntu command: tail -f /dev/null cde: image: busybox command: ping abc links: - abc