Repository: flutter
Issue: Installation on Alpine Linux container: unable to 'pub upgrade'
Labels: tool,platform-linux,has reproducible steps,P3,workaround available,team-tool,triaged-tool,found in release: 3.19,found in release: 3.20

## Steps to Reproduce

Assuming the following `Dockerfile`:

```
FROM alpine

RUN apk add bash curl file git zip
RUN git clone https://github.com/flutter/flutter.git
ENV PATH="$PATH:/flutter/bin"
RUN flutter channel stable --verbose
```

1. Go to the directory containing the `Dockerfile`
2. Build it with `docker build -t flutter-container .`

## Logs

<details>
<summary>Logs</summary>

```
Sending build context to Docker daemon  775.3MB
Step 1/5 : FROM alpine
 ---> 389fef711851
Step 2/5 : RUN apk add bash curl file git zip
 ---> Running in 601ee9be037e
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/15) Installing ncurses-terminfo-base (6.2_p20200523-r0)
(2/15) Installing ncurses-libs (6.2_p20200523-r0)
(3/15) Installing readline (8.0.4-r0)
(4/15) Installing bash (5.0.17-r0)
Executing bash-5.0.17-r0.post-install
(5/15) Installing ca-certificates (20191127-r4)
(6/15) Installing nghttp2-libs (1.41.0-r0)
(7/15) Installing libcurl (7.69.1-r3)
(8/15) Installing curl (7.69.1-r3)
(9/15) Installing libmagic (5.38-r0)
(10/15) Installing file (5.38-r0)
(11/15) Installing expat (2.2.9-r1)
(12/15) Installing pcre2 (10.35-r0)
(13/15) Installing git (2.26.2-r0)
(14/15) Installing unzip (6.0-r8)
(15/15) Installing zip (3.0-r8)
Executing busybox-1.31.1-r19.trigger
Executing ca-certificates-20191127-r4.trigger
OK: 31 MiB in 29 packages
Removing intermediate container 601ee9be037e
 ---> e7ce99575d0f
Step 3/5 : RUN git clone https://github.com/flutter/flutter.git
 ---> Running in 3fa7a78da851
Cloning into 'flutter'...
Removing intermediate container 3fa7a78da851
 ---> affa205142e3
Step 4/5 : ENV PATH="$PATH:/flutter/bin"
 ---> Running in c5bc8818015f
Removing intermediate container c5bc8818015f
 ---> c2e90c0d5be7
Step 5/5 : RUN flutter channel stable --verbose
 ---> Running in 6c53e8f5d0ad
Downloading Dart SDK from Flutter engine 121b67fb8594ab8db655427537676d37773e8cdd...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  174M  100  174M    0     0  24.1M      0  0:00:07  0:00:07 --:--:-- 25.1M
Building flutter tool...
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (8 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (7 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (6 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (5 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (4 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (3 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (2 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (1 tries left)
Command 'pub upgrade' still failed after 10 tries, giving up.
The command '/bin/sh -c flutter channel stable --verbose' returned a non-zero code: 1
```

Running the container (with `docker run -it --entrypoint /bin/bash flutter-container`) and running `flutter doctor -v` gives the same output (except that the Dart SDK has been already downloaded):

```
Building flutter tool...
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (8 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (7 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (6 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (5 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (4 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (3 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (2 tries left)
/flutter/bin/cache/dart-sdk/bin/pub: line 49: /flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (1 tries left)
Command 'pub upgrade' still failed after 10 tries, giving up.
```

</details>

## Notes

The file `/flutter/bin/cache/dart-sdk/bin/dart` exists. Therefore I don't understand why I see "No such file or directory".

Using an Ubuntu image instead of Alpine (of course using `apt` instead of `apk`) works as expected, without the error that I have reported.

Specifying `USER root` in the `Dockerfile` doesn't solve the issue.

## Related issues

- [38799](https://github.com/flutter/flutter/issues/38799)
- [12666](https://github.com/flutter/flutter/issues/12666)
- possibly others, I suppose

Thank you in advance for any help.