6

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?

  • Possible duplicate of [ERROR: In file './docker-compose.yml', volume must be a mapping not a string](https://stackoverflow.com/questions/41334488/error-in-file-docker-compose-yml-volume-must-be-a-mapping-not-a-string) – Dhia Apr 20 '18 at 09:24
  • @DhiaTN I thought so too but in that one the person isn't trying to map directories in Wordpress as well. –  Apr 20 '18 at 09:31

4 Answers4

7

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:

PKV
  • 424
  • 4
  • 6
1

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:
1

that's will fix it and it works for me

volumes:
  db_data:
    driver: local
Fahd Rahali
  • 451
  • 4
  • 6
0
version: '3.3'

serivces:
  db:
    image: mysql:5.7
    command: bash -c "mkdir -p /var/lib/mysql/"
    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: {}

save as docker-compose.yml
    cd wordpress
    docker-compose up