4

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?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Aurimas Deimantas
  • 671
  • 1
  • 10
  • 29
  • 1
    The web server should be listening for connections on 0.0.0.0, check [this answer](https://stackoverflow.com/a/56967978) and the port needs to be published (is “ports” indeed) – masseyb Sep 02 '19 at 06:05
  • Note: the docker daemon volume mapping is incorrect (“/var/run/docker.sock:/var/run/docker.sock”). – masseyb Sep 02 '19 at 06:12
  • 1
    Thank you, @masseyb, you saved my day again. It's working now. However, another issue appeared. Investigating it now – Aurimas Deimantas Sep 02 '19 at 06:38
  • Sure - added an [answer](https://stackoverflow.com/a/57752520/1423507) with link for details regarding `0.0.0.0`. – masseyb Sep 02 '19 at 07:29

2 Answers2

2

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"] 
masseyb
  • 3,745
  • 1
  • 17
  • 29
0

You are missing port in your docker-compose file

version: '3.1'
services:
  api:
    container_name: flutter-web-test
    restart: always
    image: flutter-web-test
    port:
      - "5001":"5001"
    build:
      context: ./
    volumes:
      - //var/run/docker.sock:/var/run/docker.sock
    command: ["flutter", "pub", "global", "run", "webdev", "serve", "web:5001"]
Rafaf Tahsin
  • 7,652
  • 4
  • 28
  • 45
  • 1
    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``` – Aurimas Deimantas Sep 02 '19 at 04:19