Skip to content

COPY --from fails when source path involves a symlink #974

@cstrahan

Description

@cstrahan

Here's my Dockerfile, with various sensitive names and paths changed, but otherwise unchanged:

# syntax=docker/dockerfile:experimental

# Build stage
FROM ubuntu:18.10 as builder

RUN apt-get update && \
    apt-get install -y automake ca-certificates cmake git g++ libtool m4 patch pkg-config python unzip wget curl zip zlib1g-dev ninja-build clang-7

RUN wget -O bazel.sh https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel-0.24.1-installer-linux-x86_64.sh && \
    chmod 755 bazel.sh && \
    ./bazel.sh

WORKDIR /go/src/github.com/my/project
ADD . /go/src/github.com/my/project

# add commit sha
ARG COMMIT
RUN echo "COMMIT=$COMMIT" >> /go/src/github.com/my/project/VERSION
RUN cat /go/src/github.com/my/project/VERSION

# Get ready to clone our repos
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

# Compile necessary binaries for final image
RUN --mount=type=ssh CC=clang-7 CXX=clang++-7 bazel build //:my-project


# Run stage
FROM alpine:3.7

# Necessary for cloudwatch put calls to AWS
RUN apk update && apk add --no-cache ca-certificates wget

# Our binary requires glibc
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
    wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk && \
    apk add glibc-2.29-r0.apk && \
    rm glibc-2.29-r0.apk

# Set up glibc locale
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-bin-2.29-r0.apk && \
    wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-i18n-2.29-r0.apk && \
    apk add glibc-bin-2.29-r0.apk glibc-i18n-2.29-r0.apk && \
    /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8 && \
    rm glibc-bin-2.29-r0.apk glibc-i18n-2.29-r0.apk

RUN addgroup -S gmproxy && adduser -S gmproxy -G gmproxy

WORKDIR /app

# Copy over my-project binary
COPY --from=builder /go/src/github.com/my/project/bazel-bin/linux_amd64_stripped/my-project /app/

RUN chown -R myproject:myproject /app && chgrp -R 0 /app && chmod -R g=u /app

EXPOSE 8080
EXPOSE 8081
EXPOSE 8001

USER myproject

CMD ./my-project -c config.yaml

I build with DOCKER_BUILDKIT=1 docker build --ssh default -f docker/alpine/Dockerfile ., and this is the error I get:

=> ERROR [stage-1 6/7] COPY --from=builder /go/src/github.com/my/project/bazel-bin/linux_amd64_stripped/my-project /app/                                                                                                           0.0s
------
 > [stage-1 6/7] COPY --from=builder /go/src/github.com/my/project/bazel-bin/linux_amd64_stripped/my-project /app/:
------
rpc error: code = Unknown desc =  not found: not found
$ docker version
Client:
 Version:           18.09.5
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        e8ff056
 Built:             Fri Apr 12 00:34:27 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.09.5
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       e8ff056
  Built:            Fri Apr 12 00:27:37 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions