【问题标题】:Flutter / Docker : problem running flutter pub get in docker file. Error: No pubspec.yaml file foundFlutter / Docker:在 docker 文件中运行 flutter pub get 时出现问题。错误:找不到 pubspec.yaml 文件
【发布时间】:2021-07-15 12:12:36
【问题描述】:

在尝试运行 flutter pub get 以导入依赖项时,我的 dockerfile(请参阅 dockerfile 底部)出现问题。

我得到的错误是:

=> 错误 [22/22] RUN flutter pub get 1.4s

[22/22] 运行颤振酒吧获取: #25 1.205 错误:找不到 pubspec.yaml 文件。 #25 1.205 这个命令应该从你的 Flutter 项目的根目录运行。


我尝试了不同的 WORKDIR 路径,但我似乎无法正确...任何帮助将不胜感激。


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

我的文件层次结构是:

我的 devcontainer.json 文件是:

{
    "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"
  }

【问题讨论】:

    标签: docker flutter dart dockerfile


    【解决方案1】:

    您需要使用COPY 指令将您的工作目录复制到映像中。这是在末尾添加指令后的 Dockerfile:

    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
    

    COPY . . 指令复制了从主机当前目录到镜像工作目录的所有内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 2020-09-05
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      相关资源
      最近更新 更多