在Docker的 VS Code开发容器中,flutter doctor会超时
我正在VSCode中为Flutter的 Linux桌面开发设置一个Docker开发容器,目标系统是Ubuntu 26.04。Flutter和 Docker Devcontainers对我来说都是新领域。我一直在阅读在线文档,但遇到了一些问题需要帮助。
在构建开发容器时,我能看到Dart和 Flutter的版本,但运行flutter doctor时会超时。输出如下:
root@0d90de6f5181:/workspaces/flutter_dev# dart --version
Dart SDK version: 3.11.4 (stable) (Tue Mar 24 01:02:20 2026 -0700) on "linux_x64"
root@0d90de6f5181:/workspaces/flutter_dev# flutter --version
Flutter 3.41.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision db50e20168 (12 days ago) • 2026-03-25 16:21:00 -0700
Engine • hash 5cdd32777948fa7a648fac915f8da7120ac7e97a (revision 425cfb54d0) (11 days ago) • 2026-03-25 20:14:42.000Z
Tools • Dart 3.11.4 • DevTools 2.54.2
root@0d90de6f5181:/workspaces/flutter_dev# flutter doctor -vv
[ +18 ms] Unable to locate an Android SDK.
[ +2 ms] executing: uname -m
[ +3 ms] Exit code 0 from: uname -m
[ ] x86_64
[ +5 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[ ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[ ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[ ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[ ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[ ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[ +1 ms] executing: [/workspaces/flutter_dev/flutter/] git -c log.showSignature=false log HEAD -n 1 --pretty=format:%ad --date=iso
[ +3 ms] Exit code 0 from: git -c log.showSignature=false log HEAD -n 1 --pretty=format:%ad --date=iso
[ ] 2026-03-25 16:21:00 -0700
[ +11 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[ ] Artifact Instance of 'FlutterEngineStamp' is not required, skipping update.
[ ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[ +1 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +37 ms] executing: [/workspaces/flutter_dev/] /workspaces/flutter_dev/flutter/bin/cache/dart-sdk/bin/dart pub --suppress-analytics --color --directory flutter/packages/flutter_tools get --example
[+5331 ms] Resolving dependencies in `flutter/packages/flutter_tools`...
Downloading packages...
_fe_analyzer_shared 92.0.0 (98.0.0 available)
analyzer 9.0.0 (12.0.0 available)
archive 3.6.1 (4.0.9 available)
async 2.13.0 (2.13.1 available)
built_value 8.12.1 (8.12.5 available)
dart_style 3.1.3 (3.1.8 available)
dds 5.1.0 (5.3.0 available)
devtools_shared 12.0.0 (12.1.0 available)
dwds 26.2.3 (27.0.0 available)
ffi 2.1.4 (2.2.0 available)
hooks 1.0.0 (1.0.2 available)
hooks_runner 1.0.1 (1.1.1 available)
js 0.7.2 (discontinued)
json_annotation 4.9.0 (4.11.0 available)
json_rpc_2 4.0.0 (4.1.0 available)
meta 1.17.0 (1.18.2 available)
mustache_template 2.0.2 (2.0.4 available)
petitparser 7.0.1 (7.0.2 available)
source_span 1.10.1 (1.10.2 available)
test 1.30.0 (1.31.0 available)
test_api 0.7.10 (0.7.11 available)
test_core 0.6.16 (0.6.17 available)
unified_analytics 8.0.10 (8.0.14 available)
usage 4.1.1 (discontinued)
uuid 4.5.2 (4.5.3 available)
watcher 1.2.0 (1.2.1 available)
yaml_edit 2.2.3 (2.2.4 available)
Got dependencies in `flutter/packages/flutter_tools`!
2 packages are discontinued.
25 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
[ +2 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[ ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[ ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[ ] Artifact Instance of 'FlutterEngineStamp' is not required, skipping update.
[ ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[ ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[ ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[ ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[ +39 ms] executing: [/workspaces/flutter_dev/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%ar
[ +3 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%ar
[ ] 12 days ago
[ +21 ms] [✓] Flutter (Channel stable, 3.41.6, on Ubuntu Resolute Raccoon (development branch) 6.17.0-20-generic, locale en_US.UTF-8) [27ms]
[ ] • Flutter version 3.41.6 on channel stable at /workspaces/flutter_dev/flutter
[ ] • Upstream repository https://github.com/flutter/flutter.git
[ ] • Framework revision db50e20168 (12 days ago), 2026-03-25 16:21:00 -0700
[ ] • Engine revision 425cfb54d0
[ ] • Dart version 3.11.4
[ ] • DevTools version 2.54.2
[ +1 ms] • Feature flags: no-enable-web, enable-linux-desktop, no-enable-macos-desktop, no-enable-windows-desktop, no-enable-android, no-enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file,
enable-lldb-debugging,
enable-uiscene-migration
This is taking an unexpectedly long time...⣟
[+269995 ms] [☠] Linux toolchain - develop for Linux desktop (the doctor check crashed)
[ ] ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues.
[ ] ✗ Exception: Linux toolchain - develop for Linux desktop exceeded maximum allowed duration of 0:04:30.000000
[ ] •
[ +5 ms] [✓] Connected device (1 available) [19ms]
[ ] • Linux (desktop) • linux • linux-x64 • Ubuntu Resolute Raccoon (development branch) 6.17.0-20-generic
[ +4 ms] [✓] Network resources [211ms]
[ ] • All expected network resources are available.
[ ] ! Doctor found issues in 1 category.
[ +2 ms] "flutter doctor" took 275,460ms.
[ +24 ms] Running 2 shutdown hooks
[ +1 ms] Shutdown hooks complete
[ +168 ms] exiting with code 0
root@0d90de6f5181:/workspaces/flutter_dev#
下面是init_dev.sh: (对于 /workspaces和 /workspaces/flutter的行可能没用。我在为解决“Fatal: Not a git repository”问题而苦苦挣扎时添加了这些,后来通过GIT_WORK_TREE解决了。)
#!/bin/bash
git config --global --add safe.directory /workspaces
git config --global --add safe.directory /workspaces/flutter_dev
git config --global --add safe.directory /workspaces/flutter_dev/flutter
flutter --disable-analytics
下面是post_start_dev.sh:
#!/bin/bash
flutter config --no-enable-android
flutter config --no-enable-ios
flutter config --no-enable-web
flutter config --no-enable-macos-desktop
flutter config --no-enable-windows-desktop
下面是Dockerfile:
# Use Ubuntu 26.04 as the base image
FROM ubuntu:26.04
# Set locale variables
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=America/New_York
ENV GIT_DISCOVERY_ACROSS_FILESYSTEM=1
ENV GIT_DIR=/workspaces/flutter_dev/flutter/.git
ENV GIT_WORK_TREE=/workspaces/flutter_dev/flutter
# Install needed software
RUN apt-get update && \
apt-get install -y \
locales \
curl \
unzip \
clang \
cmake \
ninja-build \
pkg-config \
libstdc++-12-dev \
mesa-utils \
git \
libgtk-3-dev && \
echo "set -o vi" >> /root/.bashrc
Flutter安装其实很简单:
tar -xvf /home/gene/Downloads/flutter_linux_3.41.6-stable.tar.xz -C /home/gene/flutter_dev
谢谢你的帮助。
解决方案
站点管理员之一建议我尝试这样运行:
flutter config --no-enable-linux-desktop
并看看flutter doctor的输出。这让它在没有超时的情况下完成,并显示没有可用设备。他们还建议我的X11显示设置看起来有问题。在研究这些问题后,我按以下步骤操作。在VSCode的终端里运行了以下命令:
flutter config --enable-linux-desktop
flutter create .
这在我的开发目录中创建了缺失的目录和文件。我还更新了devcontainer.json文件,添加了Display和 X11设置:
{
"build": {
"dockerfile": "Dockerfile"
},
"containerEnv": {
"DISPLAY": "${localEnv:DISPLAY}"
},
"mounts": [
"source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind",
"source=${localWorkspaceFolder}/src,target=/workspaces/flutter_dev/src,type=bind",
"source=${localWorkspaceFolder}/include,target=/workspaces/flutter_dev/include,type=bind"
],
"remoteEnv": {
"PATH": "${containerEnv:PATH}:/workspaces/flutter_dev/flutter/bin"
},
"initializeCommand": [
"${localWorkspaceFolder}/init_dev.sh"
],
"postStartCommand": [
"/workspaces/flutter_dev/post_start_dev.sh"
]
}
请注意,我的.bashrc已经包含了:
xhost +local:docker
现在flutter doctor显示一切正常。谢谢。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。