title: How can I use Hashicorp Packer to creat EC2 image that runs docker image on startup?
body: <p>I am trying to build an Amazon AMI that contains docker running as a daemon, runs a particular image with a mounted volume from the host, and installs some software and data inside the docker image (which will land in the mounted volume). I'd like the resulting AMI to run the same docker image on startup with the same mounted volume.  The goal is to build an EC2 image that uses a pre-built docker image that other users could use outside EC2 to do the same installation process to enable non-Amazon users to reproduce the process. The AMI piece is to facilitate a group of users to have a simple user experience. </p>
  
  <p>I have used Packer in the past for something similar (<a href="https://github.com/seandavi/terraform-can/tree/master/packer" rel="nofollow noreferrer">https://github.com/seandavi/terraform-can/tree/master/packer</a>), but I'd like to introduce the docker piece and am not clear on the approach to take. Any examples or pointers are appreciated, but the process seems like:</p>
  
  <p>Inside packer build:</p>
  
  <ol>
  <li>install docker engine</li>
  <li>run docker image with mounted volume</li>
  <li>docker exec into the image to install software and data to mounted volume</li>
  </ol>
  
  <p>How do I set up the AMI via packer to run the same image with mounted volume at startup of the AMI after build?</p>