{"action":"created","issue":{"url":"https://api.github.com/repos/docker/docker/issues/1136","labels_url":"https://api.github.com/repos/docker/docker/issues/1136/labels{/name}","comments_url":"https://api.github.com/repos/docker/docker/issues/1136/comments","events_url":"https://api.github.com/repos/docker/docker/issues/1136/events","html_url":"https://github.com/docker/docker/issues/1136","id":16401258,"number":1136,"title":"Dockerfile ADD does not understand ENV variables","user":{"login":"fmd","id":2799915,"avatar_url":"https://avatars.githubusercontent.com/u/2799915?v=3","gravatar_id":"","url":"https://api.github.com/users/fmd","html_url":"https://github.com/fmd","followers_url":"https://api.github.com/users/fmd/followers","following_url":"https://api.github.com/users/fmd/following{/other_user}","gists_url":"https://api.github.com/users/fmd/gists{/gist_id}","starred_url":"https://api.github.com/users/fmd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmd/subscriptions","organizations_url":"https://api.github.com/users/fmd/orgs","repos_url":"https://api.github.com/users/fmd/repos","events_url":"https://api.github.com/users/fmd/events{/privacy}","received_events_url":"https://api.github.com/users/fmd/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/docker/docker/milestones/9","html_url":"https://github.com/docker/docker/milestones/0.6.0","labels_url":"https://api.github.com/repos/docker/docker/milestones/9/labels","id":384104,"number":9,"title":"0.6.0","description":"","creator":{"login":"shykes","id":29565,"avatar_url":"https://avatars.githubusercontent.com/u/29565?v=3","gravatar_id":"","url":"https://api.github.com/users/shykes","html_url":"https://github.com/shykes","followers_url":"https://api.github.com/users/shykes/followers","following_url":"https://api.github.com/users/shykes/following{/other_user}","gists_url":"https://api.github.com/users/shykes/gists{/gist_id}","starred_url":"https://api.github.com/users/shykes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shykes/subscriptions","organizations_url":"https://api.github.com/users/shykes/orgs","repos_url":"https://api.github.com/users/shykes/repos","events_url":"https://api.github.com/users/shykes/events{/privacy}","received_events_url":"https://api.github.com/users/shykes/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":53,"state":"closed","created_at":"2013-07-22T16:35:11Z","updated_at":"2013-10-22T21:39:32Z","due_on":"2013-08-22T07:00:00Z","closed_at":"2013-08-27T17:19:45Z"},"comments":5,"created_at":"2013-07-05T12:33:02Z","updated_at":"2015-08-03T15:12:52Z","closed_at":"2013-07-29T21:02:19Z","body":"When writing a Dockerfile, ADD does not understand ENV variables, or system environment variables; i.e.\r\n\r\n    #Dockerfile \r\n    #Folder also contains a file named 'myfile'\r\n    FROM base\r\n    ENV MYVAR hello\r\n    \r\n    RUN echo $MYVAR\r\n    #hello   \r\n \r\n    RUN mkdir /$MYVAR\r\n    #Creates /hello/\r\n\r\n    ADD ./myfile /$MYVAR/\r\n    #Creates /$MYVAR/ and inserts 'myfile' into it.\r\n\r\nResults:\r\n\r\n    $ docker commit e859431974c1 fmdud/test\r\n    $ docker run -i -t fmdud/test /bin/bash\r\n    $ ls | grep -i myvar\\|hello\r\n\r\n    $MYVAR\r\n    hello\r\n\r\n    $ cd /\\$MYVAR && ls\r\n\r\n    myfile\r\n\r\nAt the moment, the workaround is:\r\n\r\n    #Dockerfile \r\n    #Folder also contains a file named 'myfile'\r\n    FROM base\r\n    ENV MYVAR hello\r\n\r\n    RUN mkdir /$MYVAR\r\n    #Creates /hello/\r\n\r\n    ADD ./myfile /tmp/\r\n    #Adds the file into /tmp/\r\n\r\n    RUN mv /tmp/myfile /$MYVAR/\r\n    #Moves the file into /hello/\r\n"},"comment":{"url":"https://api.github.com/repos/docker/docker/issues/comments/127273481","html_url":"https://github.com/docker/docker/issues/1136#issuecomment-127273481","issue_url":"https://api.github.com/repos/docker/docker/issues/1136","id":127273481,"user":{"login":"thaJeztah","id":1804568,"avatar_url":"https://avatars.githubusercontent.com/u/1804568?v=3","gravatar_id":"","url":"https://api.github.com/users/thaJeztah","html_url":"https://github.com/thaJeztah","followers_url":"https://api.github.com/users/thaJeztah/followers","following_url":"https://api.github.com/users/thaJeztah/following{/other_user}","gists_url":"https://api.github.com/users/thaJeztah/gists{/gist_id}","starred_url":"https://api.github.com/users/thaJeztah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thaJeztah/subscriptions","organizations_url":"https://api.github.com/users/thaJeztah/orgs","repos_url":"https://api.github.com/users/thaJeztah/repos","events_url":"https://api.github.com/users/thaJeztah/events{/privacy}","received_events_url":"https://api.github.com/users/thaJeztah/received_events","type":"User","site_admin":false},"created_at":"2015-08-03T15:12:52Z","updated_at":"2015-08-03T15:12:52Z","body":"@7specialgems it works, but there's one thing you're overlooking in your example; each instruction runs in a new container, and although *filesystem* changes and *environmental* variables set via `ENV` are preserved, other things are not.\r\n\r\n```Dockerfile\r\nFROM  centos:latest\r\nRUN mkdir /foo-bar\r\nRUN cd /foo-bar\r\nRUN pwd\r\n# outputs \"/\"\r\nRUN cd /foo-bar && pwd\r\n#outputs /foo-bar\r\n```\r\n\r\nThe ENV is actually set (and preserved), and usable in the `RUN` instruction\r\n\r\n```Dockerfile \r\nFROM centos:latest\r\nENV BLABLA hello\r\nRUN echo $BLABLA \r\n# outputs: \"hello\"\r\n```\r\n"}}