简体   繁体   中英

In file './docker-compose.yml', volume must be a mapping, not an array

Trying to run this Docker Compose file produces an error:

In file './docker-compose.yml', volume must be a mapping, not an array.

version: '3'
services:
        dbos:
                image: mysql:5.7
                volumes:
                        - mysql_storage_new:/var/lib/mysql
                restart: always
                environment:
                        MYSQL_ROOT_PASSWORD: rootpass
                        MYSQL_USER: arshit
                        MYSQL_PASSWORD: redhat
                        MYSQL_DATABASE: mydb

        wordpressos:
                image: wordpress:5.1.1-php7.3-apache
                restart: always
                depends_on:
                        - dbos
                ports:
                        - 8089:80
                environment:
                        WORDPRESS_DB_HOST: dbos
                        WORDPRESS_DB_USER: arshit
                        WORDPRESS_DB_PASSWORD: redhat
                        WORDPRESS_DB_NAME: mydb
                volumes:
                        - wp_storage_new:/var/www/html
volumes:
        - wp_storage_new:
        - mysql_storage_new:

The outer volumes key should not have an array as value but an object mapping. Here, you can also check the docs .

I would also consider bumping the version of this compose file to 3.8.

version: '3'
services:
        dbos:
                image: mysql:5.7
                volumes:
                        - mysql_storage_new:/var/lib/mysql
                restart: always
                environment:
                        MYSQL_ROOT_PASSWORD: rootpass
                        MYSQL_USER: arshit
                        MYSQL_PASSWORD: redhat
                        MYSQL_DATABASE: mydb

        wordpressos:
                image: wordpress:5.1.1-php7.3-apache
                restart: always
                depends_on:
                        - dbos
                ports:
                        - 8089:80
                environment:
                        WORDPRESS_DB_HOST: dbos
                        WORDPRESS_DB_USER: arshit
                        WORDPRESS_DB_PASSWORD: redhat
                        WORDPRESS_DB_NAME: mydb
                volumes:
                        - wp_storage_new:/var/www/html
volumes:
        wp_storage_new:
        mysql_storage_new:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM