Reputation: 489
I have a problem in my dockerfile (see bottom of dockerfile) while trying to run flutter pub get in order to import dependencies.
The error I am getting is :
[22/22] RUN flutter pub get: #25 1.205 Error: No pubspec.yaml file found. #25 1.205 This command should be run from the root of your Flutter project.
I have tried different WORKDIR paths, but I can't seem to get it right... Any help will be greatly appreciated.
FROM ubuntu:18.04
RUN apt update && apt install -y curl git unzip xz-utils zip libglu1-mesa openjdk-8-jdk wget
# Update the package list and install chrome
RUN apt-get update -y
RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
RUN rm google-chrome-stable_current_amd64.deb
# Set up new user
working directory to its home directory.
RUN useradd -ms /bin/bash developer
USER developer
WORKDIR /home/developer
# Prepare Android directories and system variables
environment variable ANDROID_SDK_ROOT to the correct directory path—this will be used by Flutter.
RUN mkdir -p Android/sdk
ENV ANDROID_SDK_ROOT /home/developer/Android/sdk
RUN mkdir -p .android && touch .android/repositories.cfg
# Set up Android SDK
RUN wget -O sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN unzip sdk-tools.zip && rm sdk-tools.zip
RUN mv tools Android/sdk/tools
RUN cd Android/sdk/tools/bin && yes | ./sdkmanager --licenses
RUN cd Android/sdk/tools/bin && ./sdkmanager "build-tools;29.0.2" "patcher;v4" "platform-tools" "platforms;android-29" "sources;android-29"
RUN cd Android/sdk/tools/bin && ./sdkmanager --install "cmdline-tools;latest"
ENV PATH "$PATH:/home/developer/Android/sdk/platform-tools"
# Download Flutter SDK
RUN git clone https://github.com/flutter/flutter.git
ENV PATH "$PATH:/home/developer/flutter/bin"
#RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
# && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
#RUN apt-get update && apt-get -y install google-chrome-stable
RUN flutter config --enable-web
RUN flutter doctor --android-licenses
# Run basic check to download Dart SDK
RUN flutter doctor
WORKDIR /home/developer/workspace/dev-800-mobile
RUN flutter pub get
My files hierarchy is :
And my devcontainer.json file is :
{
"name": "docker-flutter-test",
"context": "..",
"dockerFile": "../Dockerfile",
"remoteUser": "developer",
"settings": {
"terminal.integrated.shell.linux": null
},
"runArgs": ["--privileged"],
"extensions": ["dart-code.flutter"],
"workspaceMount": "source=${localWorkspaceFolder}/workspace,target=/home/developer/workspace,type=bind,consistency=delegated",
"workspaceFolder": "/home/developer/workspace"
}
Upvotes: 0
Views: 1647
Reputation: 1
Based on your previous comments, it looks like your pubspec.yaml file is located at:
/home/developer/workspace/dev-800-mobile/pubspec.yaml
so you need to set your WORKDIR
to that directory before running flutter pub get command in your Dockerfile
.
so, in the end, modify like this :
#Copy everything from the current directory of the host to the working directory of the image.
COPY . .
WORKDIR app/workspace/dev-800-mobile
RUN flutter pub get
I hope this solves the problem
Upvotes: 0
Reputation: 319
You need to copy your working directory into the image using the COPY
instruction. Here's your Dockerfile after adding the instruction at the end:
FROM ubuntu:18.04
RUN apt update && apt install -y curl git unzip xz-utils zip libglu1-mesa openjdk-8-jdk wget
# Update the package list and install chrome
RUN apt-get update -y
RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
RUN rm google-chrome-stable_current_amd64.deb
# Set up new user
working directory to its home directory.
RUN useradd -ms /bin/bash developer
USER developer
WORKDIR /home/developer
# Prepare Android directories and system variables
environment variable ANDROID_SDK_ROOT to the correct directory path—this will be used by Flutter.
RUN mkdir -p Android/sdk
ENV ANDROID_SDK_ROOT /home/developer/Android/sdk
RUN mkdir -p .android && touch .android/repositories.cfg
# Set up Android SDK
RUN wget -O sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN unzip sdk-tools.zip && rm sdk-tools.zip
RUN mv tools Android/sdk/tools
RUN cd Android/sdk/tools/bin && yes | ./sdkmanager --licenses
RUN cd Android/sdk/tools/bin && ./sdkmanager "build-tools;29.0.2" "patcher;v4" "platform-tools" "platforms;android-29" "sources;android-29"
RUN cd Android/sdk/tools/bin && ./sdkmanager --install "cmdline-tools;latest"
ENV PATH "$PATH:/home/developer/Android/sdk/platform-tools"
# Download Flutter SDK
RUN git clone https://github.com/flutter/flutter.git
ENV PATH "$PATH:/home/developer/flutter/bin"
#RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
# && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
#RUN apt-get update && apt-get -y install google-chrome-stable
RUN flutter config --enable-web
RUN flutter doctor --android-licenses
# Run basic check to download Dart SDK
RUN flutter doctor
# Copy everything from the current directory of host to the working directory of the image.
COPY . .
WORKDIR /home/developer/workspace/dev-800-mobile
RUN flutter pub get
The COPY . .
instruction copy's everything from the current directory of host to the working directory of the image.
Upvotes: 0