Failed to solve with frontend gateway.v0: exit code: 1 when build with experimental syntax

When build a dockerfile with experiment syntax:

# syntax=docker/dockerfile-upstream:experimental

it gives error:

DOCKER_BUILDKIT=1 docker build -t nearcore -f Dockerfile .
[+] Building 0.3s (4/4) FINISHED                                                                                                                                                                                                 
 => [internal] load .dockerignore                                                                                                                                                                                           0.0s
 => => transferring context: 186B                                                                                                                                                                                           0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                        0.0s
 => => transferring dockerfile: 1.43kB                                                                                                                                                                                      0.0s
 => resolve image config for                                                                                                                                              0.1s
 => CACHED docker-image://                                                                         0.0s
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: exit code: 1
make: *** [docker-nearcore] Error 1

Above is on a ec2 instance, Docker version 19.03.2, build 6a30dfca03, amazonlinux 2.
However, same build success on a local Docker version 18.09.7, build 2d0083d so my dockerfile should be OK. Also, the problematic ec2 instance can successfully build non experimental syntax Dockerfile and run docker run hello-world, so the docker installation should be OK too. Any ideas? Thanks!