0

version: '3.0'

services:

db:

image: mysql volumes: - db_data:/var/lib/mysql

restart: always

environment: MYSQL_ROOT_PASSWORD: 1234 MYSQL_USER: wordpress MYSQL_PASSWORD: 12345

wordpress1:

depends_on: -db

image: wordpress:latest

restart: always

ports: -"8080:80"

environment: WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_HOST: db:3306

volumes: db_data:

Error as below-

ERROR: yaml.scanner.ScannerError: while scanning a simple key in "./docker-compose.yml", line 21, column 3 could not find expected ':' in "./docker-compose.yml", line 23, column 3

Can anyone please help me to resolve this issue? I am trying to resolve since past 1 hour but getting into errors one by one

2
  • 4
    Please format your question appropriately. Commented Aug 25, 2020 at 20:00
  • 1
    Please take Y minutes to learn Yaml. List elements start with a dash followed by a space followed by the element value. Commented Aug 25, 2020 at 20:05

2 Answers 2

1

The problem is probably in the definition of the wordpress1 service.

You need to add a space after the dash:

wordpress1:
  depends_on:
    - db

So instead of -db you need to have - db.

Edit:

The complete docker-compose.yml should probably look like this:

version: '3.0'

services:
  db:
    image: mysql
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 1234
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: 12345

  wordpress1:
    depends_on:
    - db
    image: wordpress:latest
    restart: always
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_HOST: db:3306

volumes:
  db_data:
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Franz, I did the same change and now it shows me ERROR: The Compose file './docker-compose.yml' is invalid because: services.wordpress1.volumes contains an invalid type, it should be an array
I did it but shows ERROR: Named volume "db_data:/var/lib/mysql:rw" is used in service "db" but no declaration was found in the volumes section.
The last volumes should probably be on the "top level" of the yaml file. See my latest edit of my answer. @RishitSheth And don't forget to mark the answer as accepted and upvote it ;-)
I tried that as well, but was getting the same error. I tried the code shown in docker documentation and it worked. both looks same but still getting error. I will try to write it again and see how it goes. Thanks much for the help, it was very helpful
1

From docker documentation, the exact code you want to run: https://docs.docker.com/compose/wordpress/

1 Comment

that works for me, but I wonder what's the issue with the YML that I wrote. both looks like identical but still mine doesn't work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.