Docker builder with CMD doesn't work

222 views
Skip to first unread message

Raghava Karthik

unread,
Oct 20, 2017, 10:10:16 AM10/20/17
to Packer
I was trying to run a command using CMD along with ENTRYPOINT (entrypoint works perfectly). 
All i want to do is load environment variables "source /etc/environment". Below packer conf with CMD isn't working. Am i missing something here?

"builders":[{
        "type": "docker",
        "name": "image_with_tomcat",
        "image": "{{user `base_image`}}",
        "commit": true,
        "pull": true,
        "changes": [
                "CMD source /etc/environment",
                "ENTRYPOINT  /usr/local/tomcat/bin/catalina.sh start && /bin/bash"
            ],
        "run_command": ["-d", "-i", "-t", "{{.Image}}", "/bin/bash"]
    }],


Rickard von Essen

unread,
Oct 20, 2017, 11:00:28 AM10/20/17
to packe...@googlegroups.com
Could you justify "doesn't work", for example what's the output of "docker inspect <sha of the resulting image>"?

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/a784d882-ebee-40b8-a306-868e161c709b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raghava Karthik

unread,
Oct 20, 2017, 5:09:24 PM10/20/17
to Packer
I can see the command " /bin/sh -c source /etc/environments" in docker inspect , but when i run the container the environment variables cannot be found to be used.

Although for now it works with  "ENTRYPOINT  source /etc/environment && /usr/local/tomcat/bin/catalina.sh start && /bin/bash". but i cant figure out why CMD is not executed.

Thanks,
Karthik

Rickard von Essen

unread,
Oct 21, 2017, 12:23:01 AM10/21/17
to packe...@googlegroups.com
It is executed but in it's own shell since you use the shell form not the exec form.

See

--
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+unsubscribe@googlegroups.com.

Raghava Karthik

unread,
Oct 23, 2017, 10:18:57 AM10/23/17
to Packer
I used "exec"  method and still i couldn't able to make CMD run, i replaced that with CMD [\"touch\", \"/tmp/environment\"]" but alas no effect.

"builders":[{
        "type": "docker",
        "name": "image_with_tomcat",
        "image": "{{user `base_image`}}",
        "commit": true,
        "pull": true,
        "changes": [
                "CMD [\"source\", \"/etc/environment\"]",
                "ENTRYPOINT [\"/usr/local/tomcat/bin/catalina.sh \",\"start\"]"
            ]
    }],
I saw the question here https://github.com/hashicorp/packer/issues/4914  , I actually didn't get what mikeroll said. Is this issue with docker commit.

sandy k

unread,
Oct 27, 2017, 11:07:07 AM10/27/17
to Packer
There is problem with your Json,

This should fix your problem https://groups.google.com/forum/#!topic/packer-tool/WJHWnEczU-4

Raghava Karthik

unread,
Oct 31, 2017, 5:38:39 AM10/31/17
to Packer
I was able to make it work using only ENTRYPOINT with script. Using CMD alone works too but the env's are loaded in another shell. 
Thanks for the reply.
Reply all
Reply to author
Forward
0 new messages