Docker bridge network & Docker-compose "yaml.parser.ParserError"

June 30, 2016 9.6k views
Docker Networking

Hi everyone!
I have an Ubuntu 14 machine with Nginx and Docker...
Nginx is set to listen to localhost:80 and forwarding requests to Docker's network, where is running a container with a second Nginx and a Laravel App.

1) if i use the default docker bridge network, i always get problem with communications between nginx on ubuntu machine and the container into docker's network. When i try to set up the "hostbindingipv4" parameter i get this error back: "error response from Deamon: driver failed programming external connectivity on endpoint. Error starting userland proxy: listen tcp 0.0.0.0:80" note that i want to modify that 0.0.0.0 ip in something like 173.17.0.1 but unsuccessfully.
How can i forward the requests to the docker container?

2) Now i'm trying to use a docker-compose configuration like seguent:

version: '2'                          

services:                             

service_laravel:                      
    container_name: service_laravel   
    restart: always                   
    build:                            
        context: .                    
        dockerfile: Dockerfile        
    networks:                         
        docker1:                      
            ipv4_address: 173.17.0.2  
        ports:                        
            - 8000:80                 

networks:                             
    docker1:                          
        driver: bridge                
        ipam:                         
            driver: default           
        config:                       
            - subnet: 173.17.0.0/16   
            gateway: 173.17.0.1       

...with this nginx configuration...

#Ubuntu Nginx 
server {                                                               

    listen 80;                                                         
    server_name localhost;                                             

    # Proxying the connections                                         
    location / {                                                       
        proxy_pass         http://173.17.0.1:8000;                     
        proxy_redirect     off;                                        
        proxy_set_header   Host $host;                                 
        proxy_set_header   X-Real-IP $remote_addr;                     
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header   X-Forwarded-Host $server_name;              
    }                                                                  
}            

...i have a Dockerfile that build the container with laravel and Nginx... but i get this error when i run "docker-compose up"

ERROR: yaml.parser.ParserError: while parsing a block collection
  in "./docker-compose.yml", line 23, column 13
expected <block end>, but found '?'
  in "./docker-compose.yml", line 24, column 13
1 comment
  • Hi,
    I am trying to use the example provided in the site
    https://docs.docker.com/compose/gettingstarted/

    Step 3: Define services
    Define a set of services using docker-compose.yml:

    Create a file called docker-compose.yml in your project directory and add the following:

    version: '2'
    services:
      web:
        build: .
        ports:
         - "5000:5000"
        volumes:
         - .:/code
        depends_on:
         - redis
      redis:
        image: redis
    

    and when I run the command docker-compose up i got the below error

    ERROR: yaml.scanner.ScannerError: while scanning for the next token
    found character '\t' that cannot start any token
    in "./docker-compose.yml", line 18, column 1
    so i removed all spaces and modified it as below

    Defines two web services, web and redis

    version: '2'
    services:
    web:
    build: .

    Build from the dockerfile from current dir

    ports:

    • "5000:5000" #Forward the exposed port 5000 on the container to port 5000 on the host machine volumes:
    • .:/code #Mounts the project directory on the host to /code inside the container directory allowing you to modify the code without having to rebuild the image depends_on:
    • redis redis: image: redis #Links the webservice to the redis service

    on trying it again i am getting an error now as

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

    Can I get some help what is wrong here.. I am using MAC.

1 Answer

Yaml weirdness, but try aligning your subnet and gateway tags:

version: '2'                          

services:                             
    service_laravel:                      
        container_name: service_laravel   
        restart: always                   
        build:                            
            context: .                    
            dockerfile: Dockerfile        
        networks:                         
            docker1:                      
                ipv4_address: 173.17.0.2  
            ports:                        
                - 8000:80                 

networks:                             
    docker1:                          
        driver: bridge                
        ipam:                         
            driver: default           
        config:                       
            - subnet: 173.17.0.0/16   
              gateway: 173.17.0.1       
  • Really weird...
    Error changed in

    ERROR: In file './docker-compose.yml', service must be a mapping, not a NoneType.
    
    • @andreafranchini - Welp, don't know. But I'd temporarily comment out the restart tag since I haven't seen this in a service context before.

    • @andreafranchini - I got it to parse on my version, docker-compose version 1.6.2, build 4d72027, but I had to comment out the ipv4_address tag as it wasn't being recognized.

      version: '2'
      
      services:
          service_laravel:
              container_name: service_laravel
              restart: always
              build:
                  context: .
                  dockerfile: Dockerfile
              ports:
                  - "8000:80"
              networks:
                  docker1:
      ###                ipv4_address: 173.17.0.2  
      
      networks:
          docker1:
              driver: bridge
              ipam:
                  driver: default
                  config:
                  - subnet: 173.17.0.0/24
                    gateway: 173.17.0.1
      
      
      • I have the same docker-compose version and build.
        By the way if we run

        docker run --help
        

        we can read the flag

        --ip            Container IPv4 address (e.g. 172.30.100.104)
        

        So it seems that we can really set a static ip to a container, why with docker-compose we can't?

        • AUTOSOLVED

          error response from Deamon: driver failed programming external connectivity on endpoint. Error starting userland proxy: listen tcp 0.0.0.0:80"
          

          there was just another instance of nginx listening there.

          How can i forward the requests to the docker container?
          

          Port mapping between containers and localhost, or let be visible only a reverse proxy that will connect with containers by their local ip in docker network.
          My issue was to have a bad configuration of nginx.

Have another answer? Share your knowledge.