升级docker-compose到版本3

时间:2017-05-23 19:19:36

标签: docker docker-compose

这就是我的docker-compose.yml文件的样子。正如您所看到的,有一个nginx服务器,一个mongoDB,一个主应用程序,用于测试夜视仪和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')
            })
    },
}

因此,我需要通过app访问nightwatch容器,这也需要selenium。主要的app需要db

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

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

1 个答案:

答案 0 :(得分:1)

这应该足够了:

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

您不需要配置额外的网络,而不是compose提供的默认网络。

链接容器仍然配置为如此。试试这个:

version: "3"

services:
  abc:
    image: ubuntu
    command: tail -f /dev/null

  cde:
    image: busybox
    command: ping abc
    links:
      - abc