Reputation:
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?
Upvotes: 6
Views: 21869
Reputation: 21
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
Upvotes: 0
Reputation: 581
that's will fix it and it works for me
volumes:
db_data:
driver: local
Upvotes: 1
Reputation: 53
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:
Upvotes: 1
Reputation: 484
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:
Upvotes: 7