1

I have the following docker-compose.yml file:

    version: '3'

    services:
      proxy-nginx:
        build:./nginx
      ports:
        - 80:80

When I run `docker-compose up the console logs:

In file './docker-compose.yml', service 'proxy-nginx' must be a mapping not a string.

This answer suggests using quotes around the ports:

    version: '3'

    services:
      proxy-nginx:
        build:./nginx
      ports:
        - "80:80"

Also tried indenting ports more:

    version: '3'
    services:
      proxy-nginx:
        build:./nginx
        ports:
          - 80:80

But the result is still the same. Any ideas?

Ole
  • 41,793
  • 59
  • 191
  • 359
  • 1
    `build: ./nginx` instead of `build:./nginx`? Missing space? – Mike Doe Jul 23 '18 at 06:19
  • Possible duplicate of [Docker compose error "In file './docker-compose.yml', service 'punjab' must be a mapping not a string."](https://stackoverflow.com/questions/37632244/docker-compose-error-in-file-docker-compose-yml-service-punjab-must-be-a) – Mike Doe Jul 23 '18 at 06:22

1 Answers1

2

Try indenting ports properly:

    version: '3'
    services:
      gogs-nginx:
        build: ./nginx
        ports:
        - "80:80"

I think the problem is that the parser thinks ports is another service because of the misleading indentation. I can't blame it for that though.

Ole
  • 41,793
  • 59
  • 191
  • 359
whoan
  • 8,143
  • 4
  • 39
  • 48
  • Tried it and added it to the question. Any other ideas? – Ole Jul 23 '18 at 06:09
  • I updated the answer with quotes around the port values. I tried doing that earlier as well, but it was still not working for some reason. So I copied a snippet from the docker site (https://docs.docker.com/compose/gettingstarted/#step-3-define-services-in-a-compose-file) and changed it and now it works... – Ole Jul 23 '18 at 15:23