代码之家  ›  专栏  ›  技术社区  ›  shantanuo

在Docker Compose中声明卷

  •  0
  • shantanuo  · 技术社区  · 6 年前

    我正在使用Docker应用程序生成的Docker撰写文件

    docker-app  render | docker-compose -f - up
    

    Docker应用程序文件看起来像这样,它可以按预期工作。但我不能用卷。

    我在使用docker run命令时使用了-v参数…

    -v /my/custom3399:/etc/mysql/conf.d  
    -v /storage/mysql/datadir3399:/var/lib/mysql 
    

    如何在撰写文件中声明卷?

    # vi hello.dockerapp
    # This section contains your application metadata.
    # Version of the application
    version: 0.1.0
    # Name of the application
    name: hello
    # A short description of the application
    description:
    # Namespace to use when pushing to a registry. This is typically your Hub username.
    #namespace: myHubUsername
    # List of application maitainers with name and email for each
    maintainers:
      - name: root
        email:
    # Specify false here if your application doesn't support Swarm or Kubernetes
    targets:
      swarm: false
      kubernetes: false
    
    --
    # This section contains the Compose file that describes your application services.
    
    version: "3.5"
    services:
      mysql:
        image: ${mysql.image.version}
        environment:
          MYSQL_ROOT_PASSWORD: india${mysql.port}
        ports:
          - "${mysql.port}:3306"
    
    
    --
    # This section contains the default values for your application settings.
    mysql.image.version: shantanuo/mysql:5.7
    mysql.port: 3391
    

    更新:

    上面提到的脚本运行良好。但是一旦我添加了卷,我会得到一个错误:

    version: "3.5"
    services:
      mysql:
        image: ${mysql.image.version}
        environment:
          MYSQL_ROOT_PASSWORD: india${mysql.port}
        ports:
          - "${mysql.port}:3306"
        volumes:
          - type: volume
            source: mysql_data
            target: /var/lib/mysql
    
    volumes:
      mysql_data:
        external: true
    

    错误是:

    docker-app  render | docker-compose -f - up
    Recreating e5c833e2187d_hashi_mysql_1 ... error
    
    ERROR: for e5c833e2187d_hashi_mysql_1  Cannot create container for service mysql: Duplicate mount point: /var/lib/mysql
    
    ERROR: for mysql  Cannot create container for service mysql: Duplicate mount point: /var/lib/mysql
    ERROR: Encountered errors while bringing up the project.
    

    如注释所述,呈现的输出如下:

    #  /usr/local/bin/docker-app  render
    version: "3.5"
    services:
      mysql:
        environment:
          MYSQL_ROOT_PASSWORD: india3391
        image: shantanuo/mysql:5.7
        ports:
        - mode: ingress
          target: 3306
          published: 3391
          protocol: tcp
        volumes:
        - type: volume
          source: mysql_data
          target: /var/lib/mysql
    volumes:
      mysql_data:
        name: mysql_data
        external: true
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   shantanuo    6 年前

    # cd ..
    # mv hashi/ hashi123/
    # cd hashi123