0

I am trying to compose-up my application. Could anyone help? I am getting this error:

yaml.scanner.ScannerError: mapping values are not allowed here in ".\docker-compose.yml", line 4, column 21

here is my docker-compose file:

services:
   my-app:
     image: my-app
      container_name: myapp
      environment:
        - SERVER_PORT=8080
        - CONNECTIONSTRING=mysql-db://mysql:3306/messages
   java:
     image: openjdk:latest
     container_name: openjdk

  rabbitmq:
     image: wurstmeister/zookeeper
     environment:

    container_name: rabbitmq
     ports:
      - "5672:5672"

  erlang:
    image: erlang:latest
    container_name: erlang

  mysql-db:
    image: mysql
    container_name: mysql

    environment:
      MYSQL_DATABASE: messages
      MYSQL_USER: root
      MYSQL_PASSWORD: 1234
    ports:
      - "3306:3306"
  • Does this answer your question? [Docker-Compose file has yaml.scanner.ScannerError](https://stackoverflow.com/questions/39077526/docker-compose-file-has-yaml-scanner-scannererror) – Mostafa Hussein Apr 05 '21 at 14:17
  • `image:`, `environment:`, and `container_name:` all need to be at the same indentation level. Line 4 of your example is indented one space more than line 3, which leads to this error. (You can probably just delete `container_name:` with no ill effect.) – David Maze Apr 05 '21 at 14:27

2 Answers2

0

This is indented

image: my-app
  container_name: myapp
  environment:
     - SERVER_PORT=8080
     - CONNECTIONSTRING=mysql-db://mysql:3306/messages

try it like this

image: my-app
container_name: myapp
environment:
   - SERVER_PORT=8080
   - CONNECTIONSTRING=mysql-db://mysql:3306/messages

Indentation matters in yaml so ensure everything is properly aligned.

martynv
  • 41
  • 5
  • FYI that's not the only formatting errors, so please ensure you look through your file fully. the rabbitmq service also has improper indents, as well as you're missing hyphens for environment vars in mysql-db – martynv Apr 05 '21 at 14:22
0

your indentation is wrong, container_name and environment need to be on the same level as image (you have an extra space)

Ross G
  • 579
  • 4
  • 12
  • Are you sure that my connection string with mysql is fine? –  Apr 05 '21 at 14:43
  • I get this error "com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure" –  Apr 05 '21 at 14:44
  • 1
    mysql://mysql-db:3306/messages you had the schema and server name the wrong way around – Ross G Apr 05 '21 at 14:48
  • perfect, thanks. And how do i can send Postman requests? Is localhost or not? –  Apr 05 '21 at 14:57
  • you need to add a ports to my-app section like you did for the mysql-db but 8080 instead then it would be localhost – Ross G Apr 05 '21 at 16:20