Docker - Flutter Web deployment - Site cannot be reached

2,327

The webdev server should be listening on 0.0.0.0 like this answer.

The service ports should be mapped to the host and the docker daemon path should be /var/run/docker.sock:

version: '3.1'
services:
  api:
    container_name: flutter-web-test
    restart: always
    image: flutter-web-test
    ports:
      - "5001:5001"
    build:
      context: ./
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: ["flutter", "pub", "global", "run", "webdev", "serve", "--hostname", "0.0.0.0:5001"] 
Share:
2,327
Aurimas Deimantas
Author by

Aurimas Deimantas

Updated on December 13, 2022

Comments

  • Aurimas Deimantas
    Aurimas Deimantas over 1 year

    I'm using Docker and Flutter Web. I just finished setting up Docker and Compose for it. My Dockerfile

    FROM ubuntu:18.04
    
    ARG PROJECT_DIR=/srv/api
    ENV PATH=/opt/flutter/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    
    RUN apt-get update && \
        apt-get install -y \
            xz-utils \
            git \
            openssh-client \
            curl && \
        apt-get upgrade -y && \
        rm -rf /var/cache/apt
    
    RUN curl -L https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.7.8+hotfix.4-stable.tar.xz | tar -C /opt -xJ
    
    RUN apt-get install -y lib32stdc++6
    
    WORKDIR ${PROJECT_DIR}
    COPY ./ ./
    
    RUN flutter doctor
    RUN flutter upgrade
    RUN flutter packages pub global activate webdev
    RUN flutter packages upgrade
    

    My docker-compose.yaml

    version: '3.1'
    services:
      api:
        container_name: flutter-web-test
        restart: always
        image: flutter-web-test
        build:
          context: ./
        volumes:
          - //var/run/docker.sock:/var/run/docker.sock
        command: ["flutter", "pub", "global", "run", "webdev", "serve", "web:5001"]
    

    After executing docker-compose -f docker-compose.yaml build and docker-compose -f docker-compose.yaml up, I receive that server should be up.

    flutter-web-test | web
    
    flutter-web-test | [WARNING] Throwing away cached asset graph due to Dart SDK update.
    
    
    flutter-web-test | [INFO] Cleaning up outputs from previous builds. completed, took 76ms
    
    flutter-web-test | [INFO] Building new asset graph completed, took 2.5s
    
    flutter-web-test | [INFO] Checking for unexpected pre-existing outputs. completed, took 2ms
    
    flutter-web-test | [INFO] Serving `web` on http://127.0.0.1:5001
    

    However, when I try to connect to http://127.0.0.1:5001 - I see This site cannot be reached window.

    If I run it locally, it works perfectly fine. I believe I must have skipped something in Docker, but cannot find an issue. Anyone can help to spot an issue?

  • Aurimas Deimantas
    Aurimas Deimantas over 4 years
    Little syntax error there as is should be ports: - 5001:5001 However, after running it, same issue. Doesn't work. Error message changed though. Now it's This page isn't working