Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: In file './docker-compose.yml', service 'build' must be a mapping not a string

I am working on a php docker application.Am facing an error while trying docker-compose up command. Trying to connect a php application to mysql.

My docker compose file :-

 version: '2'
 services:
 web:
 container_name: modeloPHP5.4-Apache
 build: .
 ports:
 — 8889:80

 volumes:
 — ./www:/var/www/html

 links:
 — db

 db:
 container_name: modeloMySQL
 build:
 context: ./
 dockerfile: DockerfileDB
 volumes:
 — /var/lib/mysql

 ports:
 — 3307:3306

 environment:

 MYSQL_ROOT_PASSWORD: password
 MYSQL_USER: user
 MYSQL_PASSWORD: password
 MYSQL_DATABASE: db_test
like image 834
Ansplz Avatar asked Dec 20 '17 06:12

Ansplz


2 Answers

Docker compose files are YAML files that require indentation, due to a wrong indentation in your compose file, Docker thinks that build is a service declaration. You've a similar question here and you can follow an example in Docker docs to check how the indentation works.

like image 65
Miguel A. C. Avatar answered Sep 28 '22 02:09

Miguel A. C.


docker-compose file is using the YAML format, so you must check every space, line, new line and other syntax is correct in yaml format. you can use yaml parser to help you to check docker-compose file.

version: '2'

services:
 web:
  container_name: modeloPHP5.4-Apache
  build: .
  ports:
       - 8889:80
  volumes:
         - ./www:/var/www/html
  links:
       - db

 db:
  container_name: modeloMySQL
  build:
  context: ./
  dockerfile: DockerfileDB
  volumes:
         - /var/lib/mysql
  ports:
       - 3307:3306
  environment:
  MYSQL_ROOT_PASSWORD: password
  MYSQL_USER: user
  MYSQL_PASSWORD: password
  MYSQL_DATABASE: db_test
like image 35
Muh faris Avatar answered Sep 28 '22 02:09

Muh faris