Docker Compose Syntax Error

User
version: '3.3'

services:
nginx:
image: nginx:latest
container_name: oliver-nginx
ports:
– "3500:80"
networks:
– oliver-app-network
volumes:
– ./nginx:/etc/nginx/conf.d
– ./nginx/nginx.conf:/etc/nginx/nginx.conf
– ./applications/all4cloud-wordpress-website:/var/www/all4cloud-wordpress-website
depends_on:
– php
restart: always

php:
build:
context: ./php
container_name: oliver-php
volumes:
– ./applications/all4cloud-wordpress-website:/var/www/all4cloud-wordpress-website
expose:
– "9000"
working_dir: /var/www/all4cloud-wordpress-website
networks:
– oliver-app-network
restart: on-failure

olimysql:
image: mysql:8.0
container_name: oliver-mysql
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: site_db
MYSQL_USER: user
MYSQL_PASSWORD: userpassword
volumes:
– ./mysql/data:/var/lib/mysql
ports:
– "3306:3306"
networks:
– oliver-app-network
restart: always

adminer:
image: adminer
container_name: oliver-adminer
restart: always
ports:
– '3501:8080'
networks:
– oliver-app-network
depends_on:
– olimysql

node:
image: node:20-alpine
container_name: oliver-node
working_dir: /var/www/all4cloud-wordpress-website
volumes:
– ./sites/all4cloud-wordpress-website:/var/www/all4cloud-wordpress-website
command: bash -c "yarn install && yarn dev"
depends_on:
– php
restart: on-failure

networks:
oliver-app-network:
driver: bridge

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.php: 'olimysql'

Assistant
The error message:

ERROR: The Compose file './docker-compose.yml' is invalid because:
Unsupported config option for services.php: 'olimysql'

indicates that your `docker-compose.yml` file has a formatting issue. Specifically, it suggests that the `olimysql` service is incorrectly nested under the `php` service. This means Docker Compose thinks `olimysql` is a sub-option of `php`, which is invalid.

### Solution

You need to adjust the indentation so that all your services (`nginx`, `php`, `olimysql`, `adminer`, and `node`) are on the same level. Here's the corrected `docker-compose.yml`:

version: '3.3'

services:
  nginx:
    image: nginx:latest
    container_name: oliver-nginx
    ports:
      - "3500:80"
    networks:
      - oliver-app-network
    volumes:
      - ./nginx:/etc/nginx/conf.d
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./applications/all4cloud-wordpress-website:/var/www/all4cloud-wordpress-website
    depends_on:
      - php
    restart: always

  php:
    build:
      context: ./php
    container_name: oliver-php
    volumes:
      - ./applications/all4cloud-wordpress-website:/var/www/all4cloud-wordpress-website
    expose:
      - "9000"
    working_dir: /var/www/all4cloud-wordpress-website
    networks:
      - oliver-app-network
    restart: on-failure

  olimysql:
    image: mysql:8.0
    container_name: oliver-mysql
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: site_db
      MYSQL_USER: user
      MYSQL_PASSWORD: userpassword
    volumes:
      - ./mysql/data:/var/lib/mysql
    ports:
      - "3306:3306"
    networks:
      - oliver-app-network
    restart: always

  adminer:
    image: adminer
    container_name: oliver-adminer
    restart: always
    ports:
      - '3501:8080'
    networks:
      - oliver-app-network
    depends_on:
      - olimysql

  node:
    image: node:20-alpine
    container_name: oliver-node
    working_dir: /var/www/all4cloud-wordpress-website
    volumes:
      - ./applications/all4cloud-wordpress-website:/var/www/all4cloud-wordpress-website
    command: bash -c "yarn install && yarn dev"
    depends_on:
      - php
    restart: on-failure

networks:
  oliver-app-network:
    driver: bridge

### Key Changes:
1. **Fixed Indentation**: Ensured that all services are aligned at the same level.
2. **Corrected `node` service volume path**: The volume path was inconsistent. Adjusted it to match other services (`./applications/all4cloud-wordpress-website:/var/www/all4cloud-wordpress-website`).

### How to Apply Changes:
1. Save the updated `docker-compose.yml` file.
2. Run the following commands to restart your Docker setup:

docker-compose down
   docker-compose up --build

This should resolve the issue. Let me know if you encounter any other errors!

Leave a Comment

Your email address will not be published. Required fields are marked *