Quentin Fabrie
Quentin Fabrie

Reputation: 15

can't start docker-compose services

when I run this docker compose file I have a strange error. that you can see under the text. I'm new with dock so can anyone help me with this.

The error:

ERROR: The compose file './docker-compose.yaml is invalid because:
services.wordpress.build contains an invalid type, it should be a string, or an object

My docker-compose file:

    version: "3.7"
    services:
      db:
        build:  ./db
        container_name: db
        ports:
          - "3306:3306"
        volumes:
          - db_data:/var/lib.mysql
        environment:
          MYSQL_ROOT_PASSWORD: Test123
          MYSQL_DATABASE: wordpress
          MYSQL_USER: wordpress
          MYSQL_PASSWORD: Test123
        networks:
          website_network:
            aliases:
              - wordpress
      wordpress:
        build:
        container_name: wordpress_new
        ports:
          - "80:80"
        networks:
          website_network:
            aliases:
              - wordpress
        environment:
          WORDPRESS_DB_HOST: db:3306
          WORDPRESS_DB_USER: wordpress
          WORDPRESS_DB_PASSWORD: Test123
          WORDPRESS_DB_NAME: wordpress
    networks: 
      website_networks:
        name: website_network
    volumes:
      db_data:
          driver: local
          name: db_data

Upvotes: 1

Views: 310

Answers (2)

cam
cam

Reputation: 5228

Your services.wordpress.build config option needs a value after it like you did in services.db.build: ./db. This value represents where to find your Dockerfile and the context where Docker will try to build your image.

Check the docs on how you can specify the build option.

This is what your file should look like in the wordpress section:

  wordpress:
    build: BUILD_PATH_HERE # you need a value here if you're building a new docker image

Per the docs, note that if your Dockerfile has an alternate name or you need a special build context, you'll need to specify those values as well as an object. For example:

  wordpress:
    build:
      context: ./some/context/path # can be a relative or absolute path
      dockerfile: Dockerfile-alternate-name

Alternatively, if you're using a prebuilt image, you can specify:

  wordpress:
    image: IMAGE_NAME

Upvotes: 2

Mirronelli
Mirronelli

Reputation: 780

You are missing the build property value.

wordpress:
    build: SOMETHING NEEDS TO BE HERE
    container_name: wordpress_new

A path to where the build runs or a more complex object. Probably just the name of the folder where the container sources are. This is how it can look like: object if it is an object. And this is how it can look like if it is just a path: path

More info: https://docs.docker.com/compose/compose-file/compose-file-v3/#build

Upvotes: 1

Related Questions