{"action":"created","issue":{"url":"https://api.github.com/repos/docker/docker/issues/22810","repository_url":"https://api.github.com/repos/docker/docker","labels_url":"https://api.github.com/repos/docker/docker/issues/22810/labels{/name}","comments_url":"https://api.github.com/repos/docker/docker/issues/22810/comments","events_url":"https://api.github.com/repos/docker/docker/issues/22810/events","html_url":"https://github.com/docker/docker/issues/22810","id":155487495,"number":22810,"title":"Chown command in docker file adds a new layer when used to change the ownership of the copied directory/file","user":{"login":"ameyrk","id":13772520,"avatar_url":"https://avatars.githubusercontent.com/u/13772520?v=3","gravatar_id":"","url":"https://api.github.com/users/ameyrk","html_url":"https://github.com/ameyrk","followers_url":"https://api.github.com/users/ameyrk/followers","following_url":"https://api.github.com/users/ameyrk/following{/other_user}","gists_url":"https://api.github.com/users/ameyrk/gists{/gist_id}","starred_url":"https://api.github.com/users/ameyrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ameyrk/subscriptions","organizations_url":"https://api.github.com/users/ameyrk/orgs","repos_url":"https://api.github.com/users/ameyrk/repos","events_url":"https://api.github.com/users/ameyrk/events{/privacy}","received_events_url":"https://api.github.com/users/ameyrk/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-18T12:21:20Z","updated_at":"2016-05-18T13:15:59Z","closed_at":"2016-05-18T13:13:01Z","body":"<!--\r\nIf you are reporting a new issue, make sure that we do not have any duplicates\r\nalready open. You can ensure this by searching the issue list for this\r\nrepository. If there is a duplicate, please close your issue and add a comment\r\nto the existing issue instead.\r\n\r\nIf you suspect your issue is a bug, please edit your issue description to\r\ninclude the BUG REPORT INFORMATION shown below. If you fail to provide this\r\ninformation within 7 days, we cannot debug your issue and will close it. We\r\nwill, however, reopen it if you later provide the information.\r\n\r\nFor more information about reporting issues, see\r\nhttps://github.com/docker/docker/blob/master/CONTRIBUTING.md#reporting-other-issues\r\n\r\n---------------------------------------------------\r\nBUG REPORT INFORMATION\r\n---------------------------------------------------\r\nUse the commands below to provide key information from your environment:\r\nYou do NOT have to include this information if this is a FEATURE REQUEST\r\n-->\r\n\r\n**Output of `docker version`:**\r\n\r\n```\r\n$ docker --version\r\nDocker version 1.9.1, build a34a1d5/1.9.1\r\n\r\n```\r\n\r\n\r\n**Output of `docker info`:**\r\n\r\n```\r\n$ docker info\r\nContainers: 4\r\nImages: 180\r\nServer Version: 1.9.1\r\nStorage Driver: devicemapper\r\n Pool Name: docker-202:48-131076-pool\r\n Pool Blocksize: 65.54 kB\r\n Base Device Size: 10.74 GB\r\n Backing Filesystem:\r\n Data file: /dev/loop0\r\n Metadata file: /dev/loop1\r\n Data Space Used: 5.911 GB\r\n Data Space Total: 107.4 GB\r\n Data Space Available: 9.915 GB\r\n Metadata Space Used: 10.95 MB\r\n Metadata Space Total: 2.147 GB\r\n Metadata Space Available: 2.137 GB\r\n Udev Sync Supported: true\r\n Deferred Removal Enabled: false\r\n Deferred Deletion Enabled: false\r\n Deferred Deleted Device Count: 0\r\n Data loop file: /mnt/docker/devicemapper/devicemapper/data\r\n Metadata loop file: /mnt/docker/devicemapper/devicemapper/metadata\r\n Library Version: 1.02.93-RHEL7 (2015-01-28)\r\nExecution Driver: native-0.2\r\nLogging Driver: json-file\r\nKernel Version: 4.1.19-24.31.amzn1.x86_64\r\nOperating System: Amazon Linux AMI 2015.09\r\nCPUs: 1\r\nTotal Memory: 3.679 GiB\r\nName: ip-10-10-10-22\r\nID: V25U:OHKU:HIOQ:AW2A:V2HA:7OIB:EA4V:OTYO:CTAA:2SD4:KMXY:O536\r\n\r\n```\r\n\r\n**Additional environment details (AWS, VirtualBox, physical, etc.):**\r\n\r\n\r\n\r\n**Steps to reproduce the issue:**\r\n1. Create a docker file as below \r\nFROM tomcat\r\nRUN useradd -d /home/test test\r\nADD test123 /home/test/test123\r\nRUN chown -R test:test /home/sdpuser/test123\r\n2. mkdir test123 && cd test123 \r\n3. cp <somefile> test123 \r\n4. docker build -t test .\r\n\r\n**Describe the results you received:**\r\n\r\nWhen you do a docker history add the last you see chown is getting duplicated thus adding up 28.72 MB space. Ideally should run as a command but its a new layer of the same size. I figured this when I was building a custom image for my project and creating non root user within my containers.  Is this an expected behavior ?\r\n\r\nI have applied a workaround by changing the ownership within the hostOs.\r\n\r\ndocker history test\r\nIMAGE               CREATED             CREATED BY                                      SIZE                COMMENT\r\n**ec6211788d5f        52 seconds ago      /bin/sh -c chown -R sdpuser:sdpuser /home/sdp   28.72 MB\r\naa53295d188d        58 seconds ago      /bin/sh -c #(nop) ADD dir:f9bbeebffd367903e94   28.72 MB**\r\n10c5e8e82d47        41 minutes ago      /bin/sh -c useradd -d /home/sdpuser sdpuser     329.1 kB\r\ncdc78b94a897        6 months ago        /bin/sh -c #(nop) CMD [\"catalina.sh\" \"run\"]     0 B\r\n82f58c961431        6 months ago        /bin/sh -c #(nop) EXPOSE 8080/tcp               0 B\r\n34d8147d3641        6 months ago        /bin/sh -c set -x  && curl -fSL \"$TOMCAT_TGZ_   12.91 MB\r\n73deaaca356b        6 months ago        /bin/sh -c #(nop) ENV TOMCAT_TGZ_URL=https://   0 B\r\na1deecf5c68e        6 months ago        /bin/sh -c #(nop) ENV TOMCAT_VERSION=8.0.28     0 B\r\n8384577d6bb9        6 months ago        /bin/sh -c #(nop) ENV TOMCAT_MAJOR=8            0 B\r\na99360bba5f9        6 months ago        /bin/sh -c gpg --keyserver pool.sks-keyserver   111 kB\r\n7f0c5db847d7        6 months ago        /bin/sh -c #(nop) WORKDIR /usr/local/tomcat     0 B\r\n92bbf8c9f01c        6 months ago        /bin/sh -c mkdir -p \"$CATALINA_HOME\"            0 B\r\n7d22540101dc        6 months ago        /bin/sh -c #(nop) ENV PATH=/usr/local/tomcat/   0 B\r\n864b08468887        6 months ago        /bin/sh -c #(nop) ENV CATALINA_HOME=/usr/loca   0 B\r\n30d5a52e17ca        6 months ago        /bin/sh -c apt-get update && apt-get install    173.8 MB\r\n75fc529176f0        6 months ago        /bin/sh -c #(nop) ENV JAVA_DEBIAN_VERSION=7u8   0 B\r\n9ca451982f56        6 months ago        /bin/sh -c #(nop) ENV JAVA_VERSION=7u85         0 B\r\n927bc2c0c1e5        6 months ago        /bin/sh -c #(nop) ENV LANG=C.UTF-8              0 B\r\nb38503f73b41        6 months ago        /bin/sh -c apt-get update && apt-get install    680.7 kB\r\n4c0cc976b7bb        6 months ago        /bin/sh -c apt-get update && apt-get install    44.27 MB\r\n1d6f63d023f5        6 months ago        /bin/sh -c #(nop) CMD [\"/bin/bash\"]             0 B\r\nef2704e74ecc        6 months ago        /bin/sh -c #(nop) ADD file:3037fa9e903e9ae533   125.1 MB\r\n\r\n**Describe the results you expected:**\r\n\r\n\r\n**Additional information you deem important (e.g. issue happens only occasionally):**\r\n"},"comment":{"url":"https://api.github.com/repos/docker/docker/issues/comments/220022314","html_url":"https://github.com/docker/docker/issues/22810#issuecomment-220022314","issue_url":"https://api.github.com/repos/docker/docker/issues/22810","id":220022314,"user":{"login":"ameyrk","id":13772520,"avatar_url":"https://avatars.githubusercontent.com/u/13772520?v=3","gravatar_id":"","url":"https://api.github.com/users/ameyrk","html_url":"https://github.com/ameyrk","followers_url":"https://api.github.com/users/ameyrk/followers","following_url":"https://api.github.com/users/ameyrk/following{/other_user}","gists_url":"https://api.github.com/users/ameyrk/gists{/gist_id}","starred_url":"https://api.github.com/users/ameyrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ameyrk/subscriptions","organizations_url":"https://api.github.com/users/ameyrk/orgs","repos_url":"https://api.github.com/users/ameyrk/repos","events_url":"https://api.github.com/users/ameyrk/events{/privacy}","received_events_url":"https://api.github.com/users/ameyrk/received_events","type":"User","site_admin":false},"created_at":"2016-05-18T13:15:59Z","updated_at":"2016-05-18T13:15:59Z","body":"Thanks for the info"}}