payload: {"action":"created","issue":{"url":"https://api.github.com/repos/containers/buildah/issues/1994","repository_url":"https://api.github.com/repos/containers/buildah","labels_url":"https://api.github.com/repos/containers/buildah/issues/1994/labels{/name}","comments_url":"https://api.github.com/repos/containers/buildah/issues/1994/comments","events_url":"https://api.github.com/repos/containers/buildah/issues/1994/events","html_url":"https://github.com/containers/buildah/issues/1994","id":527708644,"node_id":"MDU6SXNzdWU1Mjc3MDg2NDQ=","number":1994,"title":" ENV variables works only if not pulled from a cached inherited layer in COPY command","user":{"login":"bundabrg","id":1607029,"node_id":"MDQ6VXNlcjE2MDcwMjk=","avatar_url":"https://avatars3.githubusercontent.com/u/1607029?v=4","gravatar_id":"","url":"https://api.github.com/users/bundabrg","html_url":"https://github.com/bundabrg","followers_url":"https://api.github.com/users/bundabrg/followers","following_url":"https://api.github.com/users/bundabrg/following{/other_user}","gists_url":"https://api.github.com/users/bundabrg/gists{/gist_id}","starred_url":"https://api.github.com/users/bundabrg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bundabrg/subscriptions","organizations_url":"https://api.github.com/users/bundabrg/orgs","repos_url":"https://api.github.com/users/bundabrg/repos","events_url":"https://api.github.com/users/bundabrg/events{/privacy}","received_events_url":"https://api.github.com/users/bundabrg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2019-11-24T14:46:59Z","updated_at":"2020-01-10T13:34:45Z","closed_at":null,"author_association":"NONE","body":"**Description**\r\n\r\nAssuming we use something like this:\r\n```\r\nCOPY --from=base ${ENVVAR} .\r\n```\r\nIf ENVVAR is defined in `base` then it works the first time I run the build command but for subsequent builds where `base` is cached the variable will be empty\r\n\r\n**Steps to reproduce the issue:**\r\n1. Create the following Dockerfile\r\n```\r\nFROM alpine:latest as base\r\n\r\n# Setup Environment\r\nENV WORK=/work\r\nWORKDIR ${WORK}\r\n\r\nRUN \\\r\n        echo base WORK=${WORK}\r\n\r\nFROM base as deps\r\n\r\nRUN \\\r\n        echo deps WORK=${WORK} && \\\r\n        touch ${WORK}/123\r\n\r\n\r\n\r\nFROM base as release\r\n\r\nRUN \\\r\n        echo releae WORK=${WORK}\r\n\r\n# Deliberately break the source with ab so we can see what WORK resolves to in error\r\nCOPY --from=deps a${WORK}b .\r\n```\r\n2. Execute `podman build . -t test`\r\nThis will obviously error but we will see something like (bolding mine): \r\n\r\nError: error building at STEP \"COPY --from=deps a${WORK}b .\": no files found matching \"/home/bundabrg/.local/share/containers/storage/overlay/a87efbebffd8217bb00e56cd4459b5ae1af7890dfd2f615c089f13915c7d1af8/merged/**a/workb**\": no such file or directory\r\n\r\n3. Execute the same command again. I get:\r\n\r\nError: error dry-running \"COPY --from=deps a${WORK}b .\": no files found matching \"/home/bundabrg/.local/share/containers/storage/overlay/854683a2c6f8053d4bb9ec110c789289cfe342005fba8e58e61481fb5cf42dda/merged/**ab**\": no such file or directory\r\n\r\n\r\n**Output of `buildah version`:**\r\n```\r\n$ buildah --version\r\nbuildah version 1.12.0-dev (image-spec 1.0.1-dev, runtime-spec 1.0.1-dev)\r\n```\r\n\r\n**Output of `podman version` if reporting a `podman build` issue:**\r\n\r\n```\r\n$ podman --version\r\npodman version 1.6.2\r\n```\r\n\r\n**Output of `cat /etc/*release`:**\r\n\r\n```\r\n cat /etc/*release\r\nDISTRIB_ID=Ubuntu\r\nDISTRIB_RELEASE=18.04\r\nDISTRIB_CODENAME=bionic\r\nDISTRIB_DESCRIPTION=\"Ubuntu 18.04.3 LTS\"\r\nNAME=\"Ubuntu\"\r\nVERSION=\"18.04.3 LTS (Bionic Beaver)\"\r\nID=ubuntu\r\nID_LIKE=debian\r\nPRETTY_NAME=\"Ubuntu 18.04.3 LTS\"\r\nVERSION_ID=\"18.04\"\r\nHOME_URL=\"https://www.ubuntu.com/\"\r\nSUPPORT_URL=\"https://help.ubuntu.com/\"\r\nBUG_REPORT_URL=\"https://bugs.launchpad.net/ubuntu/\"\r\nPRIVACY_POLICY_URL=\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\"\r\nVERSION_CODENAME=bionic\r\nUBUNTU_CODENAME=bionic\r\n\r\n```\r\n\r\n**Output of `uname -a`:**\r\n\r\n```\r\nLinux kitkat 5.0.0-37-generic #40~18.04.1-Ubuntu SMP Thu Nov 14 12:06:39 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux\r\n```\r\n\r\n**Output of `cat /etc/containers/storage.conf`:**\r\n\r\n```\r\n# storage.conf is the configuration file for all tools\r\n# that share the containers/storage libraries\r\n# See man 5 containers-storage.conf for more information\r\n\r\n# The \"container storage\" table contains all of the server options.\r\n[storage]\r\n\r\n# Default Storage Driver\r\ndriver = \"overlay\"\r\n\r\n# Temporary storage location\r\nrunroot = \"/var/run/containers/storage\"\r\n\r\n# Primary read-write location of container storage\r\ngraphroot = \"/var/lib/containers/storage\"\r\n\r\n[storage.options]\r\n# AdditionalImageStores is used to pass paths to additional read-only image stores\r\n# Must be comma separated list.\r\nadditionalimagestores = [\r\n]\r\n\r\n# Size is used to set a maximum size of the container image.  Only supported by\r\n# certain container storage drivers (currently overlay, zfs, vfs, btrfs)\r\nsize = \"\"\r\n\r\n# OverrideKernelCheck tells the driver to ignore kernel checks based on kernel version\r\noverride_kernel_check = \"true\"\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/containers/buildah/issues/comments/573037206","html_url":"https://github.com/containers/buildah/issues/1994#issuecomment-573037206","issue_url":"https://api.github.com/repos/containers/buildah/issues/1994","id":573037206,"node_id":"MDEyOklzc3VlQ29tbWVudDU3MzAzNzIwNg==","user":{"login":"geniass","id":1554295,"node_id":"MDQ6VXNlcjE1NTQyOTU=","avatar_url":"https://avatars3.githubusercontent.com/u/1554295?v=4","gravatar_id":"","url":"https://api.github.com/users/geniass","html_url":"https://github.com/geniass","followers_url":"https://api.github.com/users/geniass/followers","following_url":"https://api.github.com/users/geniass/following{/other_user}","gists_url":"https://api.github.com/users/geniass/gists{/gist_id}","starred_url":"https://api.github.com/users/geniass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geniass/subscriptions","organizations_url":"https://api.github.com/users/geniass/orgs","repos_url":"https://api.github.com/users/geniass/repos","events_url":"https://api.github.com/users/geniass/events{/privacy}","received_events_url":"https://api.github.com/users/geniass/received_events","type":"User","site_admin":false},"created_at":"2020-01-10T13:34:45Z","updated_at":"2020-01-10T13:34:45Z","author_association":"NONE","body":"Can confirm this on Fedora 30, except for me it fails on the first build attempt:\r\n```\r\nbuildah version\r\n\r\nVersion:         1.12.0\r\nGo Version:      go1.12.13\r\nImage Spec:      1.0.1-dev\r\nRuntime Spec:    1.0.1-dev\r\nCNI Spec:        0.4.0\r\nlibcni Version:  \r\nimage Version:   5.0.0\r\nGit Commit:      \r\nBuilt:           Thu Jan  1 02:00:00 1970\r\nOS/Arch:         linux/amd64\r\n```\r\n\r\nDockerfile:\r\n```\r\nFROM alpine AS base\r\nENV APP=/app\r\nRUN mkdir $APP\r\n\r\n\r\nFROM base AS int\r\nRUN echo $APP\r\nRUN echo wat > ${APP}/file.txt\r\n\r\n\r\nFROM base\r\nRUN echo $APP\r\nCOPY --from=int ${APP}/file.txt /app/\r\nRUN cat ${APP}/file.txt\r\n```\r\n\r\n```\r\n$ buildah bud\r\nSTEP 1: FROM alpine AS base\r\nSTEP 2: ENV APP=/app\r\nSTEP 3: RUN mkdir $APP\r\nGetting image source signatures\r\nCopying blob 6b27de954cca skipped: already exists\r\nCopying blob feecb97f9459 done\r\nCopying config baa7a01192 done\r\nWriting manifest to image destination\r\nStoring signatures\r\nbaa7a0119265f529bebcb7d3405dd4ed8a6cd6248f2c5c33dbe591a1188fba6b\r\nSTEP 4: FROM baa7a0119265f529bebcb7d3405dd4ed8a6cd6248f2c5c33dbe591a1188fba6b AS int\r\nSTEP 5: RUN echo $APP\r\n/app\r\nSTEP 6: RUN echo wat > ${APP}/file.txt\r\nSTEP 7: FROM baa7a0119265f529bebcb7d3405dd4ed8a6cd6248f2c5c33dbe591a1188fba6b\r\nSTEP 8: RUN echo $APP\r\n/app\r\nSTEP 9: COPY --from=int ${APP}/file.txt /app/\r\nerror dry-running \"COPY --from=int ${APP}/file.txt /app/\": no files found matching \"/home/ari/.local/share/containers/storage/overlay/8acc46882779b4486b6037521302126ad8b7efe3e9d616a840ddc2938072eb41/merged/file.txt\": no such file or directory\r\nERRO exit status 1       \r\n```"}}
other: {"actor":{"display_login":"geniass"}}