Docker-compose ps error

version: '3.3'
services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

the above is the code that I am using for an assignment and the error code I keep getting when I issue the command "docker-compose ps.

The error I seem to be having is "parsing /root/WordPress/docker-compose.yml: yaml: line 7: mapping values are not allowed in this context.

I reformatted your post. Next time please mark the whole compose file content and apply “Preformatted Text” once, instead of doing it with each and every line.

I am not able to reproduce the error message with the shared compose file. Is it possible you didn’t share the exact same compose file that actually causes the error message? Furthermore, you might want to make sure you use docker compose (v2), instead of docker-compose (v1, deprecated!)

Sorry, I copied and pasted straight from the assignment I was working on. I’ll give this a try. Thank you


Here is the file, formatted as I had it, line for line.

Please do not paste text as screenshot… Post it as text please.

version ‘3.3’

services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- 8000:80
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}

here is the code, formatted as it is supposed to be in the file and I am still getting the error in my OP. Even after using “docker compose” instead of “docker-compose”

I must admit, after your first post was kind of formatted, I expected this to be properly formatted.

Please take a look at the first post and how it’s formatted (click the edit button to see how it’s done) and format your post accordingly.

Indentation has semantics in yaml files, if I can’t see the indentation, it would cover the origin of the problem. Thus said, help us to help you!

Though, in this particular case it might be easy to spot.

The colon after version is missing. It must be version: '3.3' (regardless of the specific version used). It worked for me, because docker compose v2 ignores the version.

I had it indented properly and it did not transfer over when I hit submit. I’ll see if I can fix it.

Awkwardly enough, that was the problem. Sorry for the trouble. Cheers mate.

After checking again: it was already included in your original post. THAT is the reason it worked for me when I tried it. Though v2 still ignores the version.

I don’t know how I missed that in the code I copied.

Don’t worry, things happen :slight_smile: