Docker volume must be a mapping, not a string

15,079

Solution 1

There are certain typo errors first of, like serivces, evironment. They should spell services and environment. Also for the "... not string" error, just append ":" after your volume name like below

volumes: db_data:

Solution 2

I had the same problem just now and the key was the indentation of the volume name i.e. db_data.

I fixed it by putting the volume name on the same level of indentation as the depends_on under the wordpress service in the example above. (hit TAB)

volumes:
  mydata:

vs

volumes:
    mydata:
Share:
15,079
Admin
Author by

Admin

Updated on June 18, 2022

Comments

  • Admin
    Admin almost 2 years

    I have the following file at ./wordpress/docker-compose.yaml:

    version: '3.3'
    
    serivces:
      db:
        image: mysql:5.7
        volumes:
          - db_data:/var/lib/mysql
        restart: always
        evironment:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: wordpress
          MYSQL_USER: wordpress
          MYSQL_PASSWORD: wordpress
    
      wordpress:
        depends_on:
          - db
        image: wordpress:latest
        ports:
          - "8000:80"
        volumes:
          - ./:/var/www/html
        restart: always
        environment:
          WORDPRESS_DB_HOST: db:3306
          WORDPRESS_DB_USER: wordpress
          WORDPRESS_DB_PASSWORD: wordpress
    
    volumes:
      db_data
    

    When I run cd ./wordpress && docker-compose up -d I get the following error:

    ERROR: In file './docker-compose.yaml', volume must be a mapping, not a string.
    

    Can anyone tell me what I'm doing wrong?

  • Radek Strugalski
    Radek Strugalski over 4 years
    Still adding ":' did not help.