Docker build fails in Windows 10, but works in Linux

I have simple file to build docker image. It’s based on official ubuntu. In linux it builds well, but in Docker Desktop for Windows 10 I get some strange Python error. If fails on executing repo --version utility which is Python based.

So here is build file:

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install -y gawk wget git-core diffstat unzip texinfo \
    gcc-multilib build-essential chrpath socat cpio python python3 \
    python3-pip python3-pexpect xz-utils debianutils iputils-ping \
    libsdl1.2-dev xterm tar locales net-tools rsync sudo vim curl zstd \
    liblz4-tool libssl-dev bc lzop

# Install repo
ADD https://storage.googleapis.com/git-repo-downloads/repo /usr/local/bin/
RUN chmod 755 /usr/local/bin/repo
RUN python --version
RUN python3 --version
RUN repo --version

When I try to build it, I get this:

$ docker build --file ubuntu --tag test-ubuntu-20:latest .
#0 building with "default" instance using docker driver

#1 [internal] load build definition from ubuntu
#1 transferring dockerfile: 598B done
#1 DONE 0.0s

#2 [internal] load metadata for docker.io/library/ubuntu:20.04
#2 DONE 1.9s

#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s

#4 [1/8] FROM docker.io/library/ubuntu:20.04@sha256:ed4a42283d9943135ed87d4ee34e542f7f5ad9ecf2f244870e23122f703f91c2
#4 resolve docker.io/library/ubuntu:20.04@sha256:ed4a42283d9943135ed87d4ee34e542f7f5ad9ecf2f244870e23122f703f91c2 0.0s done
#4 DONE 0.0s

#5 https://storage.googleapis.com/git-repo-downloads/repo
#5 DONE 1.1s

#6 [2/8] RUN apt update
#6 CACHED

#7 [3/8] RUN apt install -y gawk wget git-core diffstat unzip texinfo     gcc-multilib build-essential chrpath socat cpio python python3     python3-pip python3-pexpect xz-utils debianutils iputils-ping     libsdl1.2-dev xterm tar locales net-tools rsync sudo vim curl zstd     liblz4-tool libssl-dev bc lzop
#7 CACHED

#8 [4/8] ADD https://storage.googleapis.com/git-repo-downloads/repo /usr/local/bin/
#8 DONE 0.0s

#9 [5/8] RUN chmod 755 /usr/local/bin/repo
#9 DONE 0.3s

#10 [6/8] RUN python --version
#10 0.372 Python 2.7.18
#10 DONE 0.4s

#11 [7/8] RUN python3 --version
#11 0.505 Python 3.8.10
#11 DONE 0.5s

#12 [8/8] RUN repo --version
#12 0.489   File "/usr/local/bin/repo", line 51
#12 0.489     def print(self, *args, **kwargs):
#12 0.489             ^
#12 0.489 SyntaxError: invalid syntax
#12 ERROR: process "/bin/sh -c repo --version" did not complete successfully: exit code: 1
------
 > [8/8] RUN repo --version:
0.489   File "/usr/local/bin/repo", line 51
0.489     def print(self, *args, **kwargs):
0.489             ^
0.489 SyntaxError: invalid syntax
------
ubuntu:16
--------------------
  14 |     RUN python --version
  15 |     RUN python3 --version
  16 | >>> RUN repo --version
--------------------
ERROR: failed to solve: process "/bin/sh -c repo --version" did not complete successfully: exit code: 1

View build details: docker-desktop://dashboard/build/default/default/aik63t5qkodwxdx5wvellfun1

I already googled for it, tried different base Linux images for WSL 2. Used Alpine and Ubuntu 20. None helped. Error is still same

1 Like

Happens for me as well.

Hi @zippo2

You can check this post to solve the issue, this worked for me:

Great thanks!
I also was able to solve it by installing such package in Ubuntu:
python-is-python3