Skip to content

docker build --squash can create incorrect shadowed layers #38072

@vincentwoo

Description

@vincentwoo

Description

I am building images with docker build --squash. One of my image inherits from another, and tries to COPY over a file that was previously copied in the parent. It appears that sometimes when I build with --squash, this file is not overwritten in the child and has the contents set by the parent. However, if I build afterwards without squash, it correctly copies the child's file.

vwoo@ubuntu:~/shared/execute/docker$ docker build --squash -t us.gcr.io/coderpad-1189/coderpad:vb vb
Sending build context to Docker daemon  3.584kB
Step 1/5 : FROM us.gcr.io/coderpad-1189/coderpad:csharp
 ---> 2bd6abaee988
Step 2/5 : RUN rm *.csproj
 ---> Using cache
 ---> ea17424c4927
Step 3/5 : RUN su - coderpad -c "dotnet new console --name solution --output . --language VB &&   dotnet add package System.Json &&   dotnet add package NUnitLite &&   dotnet run"
 ---> Using cache
 ---> 38b6ba62c6d7
Step 4/5 : RUN rm *.vb
 ---> Using cache
 ---> 5a0d310869ef
Step 5/5 : COPY --chown=coderpad:coderpad bin /usr/local/bin
 ---> Using cache
 ---> 6bbe60888a2c
Successfully built 399a017a0656
Successfully tagged us.gcr.io/coderpad-1189/coderpad:vb
vwoo@ubuntu:~/shared/execute/docker$ docker run --entrypoint /bin/bash  --rm -it us.gcr.io/coderpad-1189/coderpad:vb
root@841b7f8ce1eb:~# cat `which startshell`
#!/bin/bash

echo "$1" | base64 --decode > Solution.cs
dotnet build --verbosity q --no-restore --output . && dotnet exec solution.dll
root@841b7f8ce1eb:~# exit
vwoo@ubuntu:~/shared/execute/docker$ docker build -t us.gcr.io/coderpad-1189/coderpad:vb vb
Sending build context to Docker daemon  3.584kB
Step 1/5 : FROM us.gcr.io/coderpad-1189/coderpad:csharp
 ---> 2bd6abaee988
Step 2/5 : RUN rm *.csproj
 ---> Using cache
 ---> ea17424c4927
Step 3/5 : RUN su - coderpad -c "dotnet new console --name solution --output . --language VB &&   dotnet add package System.Json &&   dotnet add package NUnitLite &&   dotnet run"
 ---> Using cache
 ---> 38b6ba62c6d7
Step 4/5 : RUN rm *.vb
 ---> Using cache
 ---> 5a0d310869ef
Step 5/5 : COPY --chown=coderpad:coderpad bin /usr/local/bin
 ---> Using cache
 ---> 6bbe60888a2c
Successfully built 6bbe60888a2c
Successfully tagged us.gcr.io/coderpad-1189/coderpad:vb
vwoo@ubuntu:~/shared/execute/docker$ docker run --entrypoint /bin/bash  --rm -it us.gcr.io/coderpad-1189/coderpad:vb
root@7e1636a3b5a3:~# cat `which startshell`
#!/bin/bash

echo "$1" | base64 --decode > Solution.vb
dotnet build --verbosity q --no-restore --output . && dotnet exec solution.dll
root@7e1636a3b5a3:~#

Notice that /usr/local/bin/startshell references a file with a .cs extension in the first run, but not after running a build without squash.

Steps to reproduce the issue:

I cannot reproduce this reliably. I believe it may have something to do with layer caching.

Describe the results you received:

See above.

Describe the results you expected:

See above.

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:24:51 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:23:15 2018
  OS/Arch:          linux/amd64
  Experimental:     true

Output of docker info:

Containers: 6
 Running: 1
 Paused: 0
 Stopped: 5
Images: 429
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: none
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.15.0-36-generic
Operating System: Ubuntu 18.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.924GiB
Name: ubuntu
ID: BAB2:FH7X:Q3WS:QGFD:EXYB:PDJX:YA6P:TCLJ:427A:5M5J:NHHA:U5GC
Docker Root Dir: /data/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 32
 Goroutines: 52
 System Time: 2018-10-24T02:21:33.142252949Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support

Additional environment details (AWS, VirtualBox, physical, etc.):
Host system is ubuntu 18.04 running inside vmware fusion, locally.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions