> > I was exporting the container instead of committing it by builder. >
Exporting only dumps the filesystem into a tar, no metadata is included. But as you can see ${PATH} from "changes" is not being resolved (or it is > actually empty for some reason). > Seems to work for me: $ docker run -it sha256:134ccd664a094ef9eea184650fb24dbdad4dc59b44e81ce131d2f126e8638772 bash -c 'echo $PATH' /usr/local/texlive/2018/bin/x86_64-linux/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin On 9 March 2018 at 14:50, Ivan Ribakov <ivan.ribak...@gmail.com> wrote: > Thanks Rickard, I understand now why Env was null before - I was exporting > the container instead of committing it by builder. > > I have changed my builder to the following: > > "builders": [{ > "type": "docker", > "image": "{{user `docker_source_repo`}}:{{user `docker_source_tag`}}", > "commit": true, > "run_command": [ > "-d", > "-i", > "-t", > "--name", > "{{user `container_name`}}", > "--privileged", > "{{.Image}}", > "/bin/bash" > ], > "changes": [ > "ENV PATH=/usr/local/texlive/2018/bin/x86_64-linux/:${PATH}" > ] > }], > > > However, now, "docker inspect" shows following: > > "Env": [ > "PATH=/usr/local/texlive/2018/bin/x86_64-linux/:" > ], > > I took stripped down template from above: > { > "builders": [{ > "type": "docker", > "image": "centos:6", > "commit": true, > "run_command": [ > "-d", > "-i", > "-t", > "--privileged", > "{{.Image}}", > "/bin/bash" > ], > "changes": [ > "ENV PATH=/usr/local/texlive/2018/bin/x86_64-linux/:${PATH}" > ] > }] > } > > and ran: > > $ packer build docker.json > [...] > ==> Builds finished. The artifacts of successful builds are: > --> docker: Imported Docker image: sha256:665e385658c14cf0f19fdd5 > 84fcbbd18df0f50e281896cc6cae470ec2eee085a > > > $ docker inspect sha256:665e385658c14cf0f19fdd5 > 84fcbbd18df0f50e281896cc6cae470ec2eee085a -f "{{.Config.Env}}" > [PATH=/usr/local/texlive/2018/bin/x86_64-linux/:] > > But as you can see ${PATH} from "changes" is not being resolved (or it is > actually empty for some reason). > > I guess I'm missing something extra this time but I'm not sure where to > start looking. Any ideas? > > On Friday, 9 March 2018 12:51:27 UTC+1, Rickard von Essen wrote: >> >> This works for me: >> >> { >> "builders": [{ >> "type": "docker", >> "image": "centos:6", >> "commit": true, >> "run_command": [ >> "-d", >> "-i", >> "-t", >> "--privileged", >> "{{.Image}}", >> "/bin/bash" >> ], >> "changes": [ >> "ENV PATH=/usr/local/texlive/2018/bin/x86_64-linux/:${PATH}" >> ] >> }] >> } >> >> $ packer build docker.json >> [...] >> ==> Builds finished. The artifacts of successful builds are: >> --> docker: Imported Docker image: sha256:134ccd664a094ef9eea1846 >> 50fb24dbdad4dc59b44e81ce131d2f126e8638772 >> >> $ docker inspect sha256:134ccd664a094ef9eea1846 >> 50fb24dbdad4dc59b44e81ce131d2f126e8638772 -f "{{.Config.Env}}" >> [PATH=/usr/local/texlive/2018/bin/x86_64-linux/:/usr/local/s >> bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] >> >> >> >> On 9 March 2018 at 12:35, Rickard von Essen <rickard....@gmail.com> >> wrote: >> >>> However, I would like to use this opportunity to ask if after all there >>>> is an alternative to "--changes" that can be performed by one of >>>> provisioners. Reason I'm looking for an alternative is that I'm using >>>> Ansible playbook to provision both Docker and Vagrant images. My only >>>> option for now to set PATH correctly in Docker seems to be to duplicate >>>> PATH configuration inside Packer template and I don't like the idea of >>>> repeating the configuration for obvious reasons. >>>> >>> >>> You have two options: >>> >>> a) Either you use the same provisioner and configure bashrc or profile >>> but then you have to invoke them the same, i.e. docker exec <container> >>> bash (-l) -c test.sh >>> >>> or >>> >>> b) Use bashrc or profile in the vagrant image since that is invoking >>> bash when you ssh into it and use changes ENV PATH=... to add test.sh to >>> the path in the docker image where bash is not automatically invoked by >>> docker exec. >>> >>> >>> On 8 March 2018 at 22:05, Ivan Ribakov <ivan.r...@gmail.com> wrote: >>> >>>> Alvaro: >>>> >>>> I posted this question here because of the Packer way to build Docker >>>> images, i.e. without using Dockerfiles. I'm hoping that this place has >>>> higher concentration of people who work with Docker without Dockerfiles and >>>> as such can help me with my query. >>>> In case you are wondering, earlier snippet can be replicated using >>>> following Packer template >>>> <https://gist.github.com/IvanRibakov/fa69cc2fe87d133ff55405d384638f66> >>>> . >>>> P.S. last line in the snippet should be "docker run" not "docker exec". >>>> >>>> Rickard: >>>> >>>> Thanks again for taking your time today to help me out. Another answer >>>> <https://stackoverflow.com/a/49175304/258825> on my SO question >>>> already suggested use of "--changes": it is definitely the winning option >>>> for me at the moment. >>>> >>>> However, I would like to use this opportunity to ask if after all there >>>> is an alternative to "--changes" that can be performed by one of >>>> provisioners. Reason I'm looking for an alternative is that I'm using >>>> Ansible playbook to provision both Docker and Vagrant images. My only >>>> option for now to set PATH correctly in Docker seems to be to duplicate >>>> PATH configuration inside Packer template and I don't like the idea of >>>> repeating the configuration for obvious reasons. >>>> >>>> I appreciate that this is not an issue with Packer at all, but as >>>> mentioned earlier, seeing how this forum has a high concentration of people >>>> who work with Docker without Dockerfiles I was hoping that someone might >>>> know a better answer (and if not, could perhaps at least hint where the >>>> limitation lies). >>>> >>>> >>>> On Thursday, 8 March 2018 19:33:20 UTC+1, Rickard von Essen wrote: >>>>> >>>>> Use changes and ENV to set the PATH, see https://www.packer.io/docs >>>>> /builders/docker.html#basic-example-changes-to-metadata >>>>> >>>>> On Mar 8, 2018 7:00 PM, "Alvaro Miranda Aguilera" <kik...@gmail.com> >>>>> wrote: >>>>> >>>>>> where packer fits here ? >>>>>> >>>>>> On Thu, Mar 8, 2018 at 6:02 PM, Ivan Ribakov <ivan.r...@gmail.com> >>>>>> wrote: >>>>>> >>>>>>> I'm building a docker image and using Ansible for provisioning. I >>>>>>> would like to be able to update image's PATH variable from inside the >>>>>>> container (I don't need these changes to take effect immediately, as >>>>>>> long >>>>>>> as they are commited to an image and are available later). Is there a >>>>>>> way >>>>>>> to do it? >>>>>>> >>>>>>> To illustrate my point: >>>>>>> >>>>>>> $ docker run -itd --name test centos:6 >>>>>>> $ docker exec -it test /bin/bash >>>>>>> [root@006a9c3195b6 /]# echo 'echo SUCCESS' > /root/test.sh >>>>>>> [root@006a9c3195b6 /]# chmod +x /root/test.sh >>>>>>> [root@006a9c3195b6 /]# echo 'export PATH=/root:$PATH' > >>>>>>> /etc/profile.d/my_settings.sh >>>>>>> [root@006a9c3195b6 /]# echo 'PATH=/root:$PATH' > /etc/environment >>>>>>> [root@006a9c3195b6 /]# echo 'export PATH=/root:$PATH' > ~/.bashrc >>>>>>> [root@006a9c3195b6 /]# exit >>>>>>> $ docker commit test test-image:1 >>>>>>> $ docker exec -it test-image:1 test.sh >>>>>>> OCI runtime exec failed: exec failed: container_linux.go:296: starting >>>>>>> container process caused "exec: \"test.sh\": executable file not found >>>>>>> in $PATH": unknown >>>>>>> >>>>>>> >>>>>>> However, following works: >>>>>>> >>>>>>> $ docker run -it test-image:1 /bin/bash >>>>>>> [root@8f821c7b9b82 /]# test.sh >>>>>>> SUCCESS >>>>>>> >>>>>>> >>>>>>> Any ideas as to what I'm doing wrong? >>>>>>> >>>>>>> -- >>>>>>> This mailing list is governed under the HashiCorp Community >>>>>>> Guidelines - https://www.hashicorp.com/community-guidelines.html. >>>>>>> Behavior in violation of those guidelines may result in your removal >>>>>>> from >>>>>>> this mailing list. >>>>>>> >>>>>>> GitHub Issues: https://github.com/mitchellh/packer/issues >>>>>>> IRC: #packer-tool on Freenode >>>>>>> --- >>>>>>> You received this message because you are subscribed to the Google >>>>>>> Groups "Packer" group. >>>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>>> send an email to packer-tool...@googlegroups.com. >>>>>>> To view this discussion on the web visit >>>>>>> https://groups.google.com/d/msgid/packer-tool/e4cb8df6-fe4e- >>>>>>> 48bc-9064-64ce4cabae79%40googlegroups.com >>>>>>> <https://groups.google.com/d/msgid/packer-tool/e4cb8df6-fe4e-48bc-9064-64ce4cabae79%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>>>> . >>>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Alvaro >>>>>> >>>>>> -- >>>>>> This mailing list is governed under the HashiCorp Community >>>>>> Guidelines - https://www.hashicorp.com/community-guidelines.html. >>>>>> Behavior in violation of those guidelines may result in your removal from >>>>>> this mailing list. >>>>>> >>>>>> GitHub Issues: https://github.com/mitchellh/packer/issues >>>>>> IRC: #packer-tool on Freenode >>>>>> --- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Packer" group. >>>>>> To unsubscribe from this group and stop receiving emails from it, >>>>>> send an email to packer-tool...@googlegroups.com. >>>>>> To view this discussion on the web visit >>>>>> https://groups.google.com/d/msgid/packer-tool/CAHqq0eyK01mTY >>>>>> LZDQmxdz-U%3DWbFj39dFkcNHEDZ883nXukym9Q%40mail.gmail.com >>>>>> <https://groups.google.com/d/msgid/packer-tool/CAHqq0eyK01mTYLZDQmxdz-U%3DWbFj39dFkcNHEDZ883nXukym9Q%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>>>> . >>>>>> For more options, visit https://groups.google.com/d/optout. >>>>>> >>>>> -- >>>> This mailing list is governed under the HashiCorp Community Guidelines >>>> - https://www.hashicorp.com/community-guidelines.html. Behavior in >>>> violation of those guidelines may result in your removal from this mailing >>>> list. >>>> >>>> GitHub Issues: https://github.com/mitchellh/packer/issues >>>> IRC: #packer-tool on Freenode >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "Packer" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to packer-tool...@googlegroups.com. >>>> To view this discussion on the web visit https://groups.google.com/d/ms >>>> gid/packer-tool/60a0484d-9850-4046-82b0-0b09152b6447%40googlegroups.com >>>> <https://groups.google.com/d/msgid/packer-tool/60a0484d-9850-4046-82b0-0b09152b6447%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >> -- > This mailing list is governed under the HashiCorp Community Guidelines - > https://www.hashicorp.com/community-guidelines.html. Behavior in > violation of those guidelines may result in your removal from this mailing > list. > > GitHub Issues: https://github.com/mitchellh/packer/issues > IRC: #packer-tool on Freenode > --- > You received this message because you are subscribed to the Google Groups > "Packer" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to packer-tool+unsubscr...@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/packer-tool/1a1ec019-349e-42ef-bef8-719e588f4349%40googlegroups.com > <https://groups.google.com/d/msgid/packer-tool/1a1ec019-349e-42ef-bef8-719e588f4349%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list. GitHub Issues: https://github.com/mitchellh/packer/issues IRC: #packer-tool on Freenode --- You received this message because you are subscribed to the Google Groups "Packer" group. To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CALz9Rt94QMif17om8jWQgnSuKZKZOPumhQ9K1Gn4xTBCgeuSMA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.