subfuzion / dart-docker-slim

Create slim Docker images for Dart using subfuzion/dart:slim as the base
https://hub.docker.com/repository/docker/subfuzion/dart
Apache License 2.0
76 stars 6 forks source link

Trouble including other directories #10

Closed Dokotela closed 3 years ago

Dokotela commented 3 years ago

Thanks so much for this docker image! I've been using it successfully to run a server, and now I wanted to use it to host a Flutter Web App. My folder structure looks like this:

-njck/
  -web/
  -Dockerfile
  -pubspec.yaml
  -server.dart

The web folder is just the simple Flutter demo app with floating button and counter. My server.dart looks like this:

import 'package:get_server/get_server.dart';
void main() => runApp(GetServer(home: FolderWidget('web')));

And my docker file looks like this:

################
FROM google/dart:2.10

RUN apt -y update && apt -y upgrade

WORKDIR /app
COPY pubspec.yaml /app/pubspec.yaml
RUN dart pub get
COPY . .
RUN dart pub get --offline

RUN dart pub run build_runner build --delete-conflicting-outputs
RUN dart compile exe /app/server.dart -o /app/server

########################
FROM subfuzion/dart:slim
COPY --from=0 /app /app
EXPOSE 8080
ENTRYPOINT ["/app/server"]

I can run the server directly from the command line as:
$ dart server.dart And that runs perfectly. However, if I build and run the docker container, it will run, when I go to 0.0.0.0:8080 or localhost:8080 it just says the page can't be found.

Any idea what I'm doing wrong? Thanks!

Dokotela commented 3 years ago

Turns out I'm just an idiot and was trying to serve the website from the same directory on my computer as in my docker container (suprise! that didn't work). I've changed my server.dart file to be:

import 'package:get_server/get_server.dart'; void main() => runApp(GetServer(home: FolderWidget('./app/web')));

And my docker file is now:

################
FROM google/dart:2.10

WORKDIR /app
COPY pubspec.yaml /app/pubspec.yaml
RUN dart pub get
COPY . .
RUN dart pub get --offline
RUN dart compile exe bin/server.dart -o bin/server

########################
FROM subfuzion/dart:slim
COPY --from=0 /app/bin/server /app/bin/server
COPY --from=0 /app/web /app/web
EXPOSE 8080
ENTRYPOINT ["/app/bin/server"]

And it works like a charm.