Answers: <p>The answer depends on how you want to run the container.  There are 3 ways you could accomplish this:</p>
  
  <ol>
  <li>Since you mentioned creating a cluster, you could create a new Kubernetes cluster and run your containers in this cluster.  AWS does support creating a cluster and managing of it via the <a href="https://docs.aws.amazon.com/cli/latest/reference/eks/create-cluster.html" rel="nofollow noreferrer">CLI</a>.</li>
  <li>You can choose to run the containers as part of AWS Elastic Container Service (<a href="https://aws.amazon.com/ecs/" rel="nofollow noreferrer">ECS</a>).  This supports launching the containers via AWS Fargate (essentially a "serverless" type approach where you pay for CPU and Memory consumed) or on a standard EC2 instance.  ECS has its own <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html" rel="nofollow noreferrer">CLI</a> (separate install).  ECS will also allow you to set the ports and set inbound/outbound rules.</li>
  <li>Finally, you can choose to use the CLI to spin up an EC2 instance and then manually or via a script start the docker containers.  However, you'd be much better off choosing one of the first two options.</li>
  </ol>
  
  <p>Finally, AWS does have a <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_AWSCLI_EC2.html" rel="nofollow noreferrer">tutorial</a> that seems to go over exactly what you are trying to accomplish (configuring a container to run via the CLI).</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-20T16:46:10.197Z
Answers: I assume the second option is best suited. For now, I'll overlook the "create a cluster" part, and just go with the default cluster. So if I understand that correctly I now need to specify a task definition that uses my image that is located on ECR and needs to pull that image and then somehow start that. That's already where I am starting to struggle. I need to specify a Secrets Manager ARN or name - and I do not know the path. Since I am using an educate account my secrets are stored on rosettahub.com. How can I find the correct ARN so the task can pull my image from the ECR
Answers: Kyu96
Answers: CC BY-SA 4.0
Answers: 2019-12-20T17:02:19.297Z
Answers: You shouldn't need anything beyond the proper IAM permissions and the task definition to get things going.  Check out step 5 of the AWS tutorial I linked to for an example of deploying a busybox container via the CLI.  As for how to pull from ECR, I think you can find that information from the ECR GUI within AWS.
Answers: Wesley Rolnick
Answers: CC BY-SA 4.0
Answers: 2019-12-21T13:43:43.703Z
Answers: I am still having a hard time to get the big picture of everything, even after reading the guide you linked. 
  My docker image is on the ECR. ECS is used to run docker images on a cluster, right?
  What steps are needed in what order to get my image that is laying in the ECR to run on ECS?
  
  I somehow need to tell ECS to pull the image from the ECR (which requires certain permissions?) ...
  But before that I already need a running instance on ECS where the pull command is executed on?
  And I also need to start it somehow ..?
  I just fail to understand in what order I need to do things.
Answers: Kyu96
Answers: CC BY-SA 4.0
Answers: 2019-12-20T16:01:43.003Z
Answers: 2019-12-20T16:01:43.003Z
Answers: Wesley Rolnick
Answers: <p>In my opinion, Packer should only be used for building something like a VM or docker image. If you would like to run a VM then you could subsequently use Vagrant or docker-compose in case of docker.</p>
  
  <blockquote>
    <p>now I need a way to automatically start this docker image and make
    sure the network traffic settings are configured correctly</p>
  </blockquote>
  
  <p>If one is running k8s then one could update the tag of a docker-image that is defined in the deployment.yaml and do a <code>kubectl up</code> again.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-12-20T15:35:26.433Z
Answers: 2019-12-20T15:35:26.433Z
Answers: 030
Body: <p>I used packer to upload a docker image I created to my AWS ECR repository.</p>
  
  <p>How can I use the AWS cli to automatically locate that image, create a new cluster, set the port rules to allow all inbound and outbound traffic and then spin up the container?
  I want to automate this process so I can integrate it into packer later, as a post processor.</p>
  
  <p>Can someone explain me how I can do this?</p>
  
  <pre><code>{
      "type": "docker-push",
      "ecr_login": true,
      "aws_access_key": "&lt;snip&gt;",
      "aws_secret_key": "&lt;snipe&gt;",
      "login_server": "https://&lt;snip&gt;.dkr.ecr.eu-west-1.amazonaws.com/"
  }
  </code></pre>
  
  <p>Currently the last part of my packer script just uploads the image - now I need a way to automatically start this docker image and make sure the network traffic settings are configured correctly.</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-12-23T08:26:37.690Z
Comments: Could you indicate whether you solved the issue?
Comments: 030
Comments: CC BY-SA 4.0
Comments: 2019-12-25T15:32:40.570Z
Comments: @030 The issue not resolved but I think I should create a new thread with a more descriptive explanation of the problem.
Comments: Kyu96
Tags: <docker><amazon-web-services><deployment>
Title: AWS ECR start uploaded docker image?
UserDisplayName: Kyu96
ThreadText: # AWS ECR start uploaded docker image?
  
  (Asked by: username_0 on 2019-12-20)
  
  I used packer to upload a docker image I created to my AWS ECR repository.
  
  How can I use the AWS cli to automatically locate that image, create a new cluster, set the port rules to allow all inbound and outbound traffic and then spin up the container?
  I want to automate this process so I can integrate it into packer later, as a post processor.
  
  Can someone explain me how I can do this?
  
  ```
  {
      "type": "docker-push",
      "ecr_login": true,
      "aws_access_key": "<snip>",
      "aws_secret_key": "<snipe>",
      "login_server": "https://<snip>.dkr.ecr.eu-west-1.amazonaws.com/"
  }
  
  ```
  
  Currently the last part of my packer script just uploads the image - now I need a way to automatically start this docker image and make sure the network traffic settings are configured correctly.
  
  **Tags:** docker, amazon-web-services, deployment
  
  > **Comments:**
  > **username_1**: Could you indicate whether you solved the issue?  
  > **username_0**: @username_1 The issue not resolved but I think I should create a new thread with a more descriptive explanation of the problem.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2019-12-20. Score: 2 | Accepted answer
  
  The answer depends on how you want to run the container. There are 3 ways you could accomplish this:
  
  1. Since you mentioned creating a cluster, you could create a new Kubernetes cluster and run your containers in this cluster. AWS does support creating a cluster and managing of it via the [CLI](https://docs.aws.amazon.com/cli/latest/reference/eks/create-cluster.html).
  2. You can choose to run the containers as part of AWS Elastic Container Service ([ECS](https://aws.amazon.com/ecs/)). This supports launching the containers via AWS Fargate (essentially a "serverless" type approach where you pay for CPU and Memory consumed) or on a standard EC2 instance. ECS has its own [CLI](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html) (separate install). ECS will also allow you to set the ports and set inbound/outbound rules.
  3. Finally, you can choose to use the CLI to spin up an EC2 instance and then manually or via a script start the docker containers. However, you'd be much better off choosing one of the first two options.
  
  Finally, AWS does have a [tutorial](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_AWSCLI_EC2.html) that seems to go over exactly what you are trying to accomplish (configuring a container to run via the CLI).
  
  > **Comments:**
  > **username_0**: I assume the second option is best suited. For now, I'll overlook the "create a cluster" part, and just go with the default cluster. So if I understand that correctly I now need to specify a task definition that uses my image that is located on ECR and needs to pull that image and then somehow start that. That's already where I am starting to struggle. I need to specify a Secrets Manager ARN or name - and I do not know the path. Since I am using an educate account my secrets are stored on rosettahub.com. How can I find the correct ARN so the task can pull my image from the ECR  
  > **username_2**: You shouldn't need anything beyond the proper IAM permissions and the task definition to get things going.  Check out step 5 of the AWS tutorial I linked to for an example of deploying a busybox container via the CLI.  As for how to pull from ECR, I think you can find that information from the ECR GUI within AWS.  
  > **username_0**: I am still having a hard time to get the big picture of everything, even after reading the guide you linked.  My docker image is on the ECR. ECS is used to run docker images on a cluster, right? What steps are needed in what order to get my image that is laying in the ECR to run on ECS?  I somehow need to tell ECS to pull the image from the ECR (which requires certain permissions?) ... But before that I already need a running instance on ECS where the pull command is executed on? And I also need to start it somehow ..? I just fail to understand in what order I need to do things.  
  
  ---
  
  ### Answer by username_1 on 2019-12-20. Score: 1
  
  In my opinion, Packer should only be used for building something like a VM or docker image. If you would like to run a VM then you could subsequently use Vagrant or docker-compose in case of docker.
  
  > now I need a way to automatically start this docker image and make
  > sure the network traffic settings are configured correctly
  
  If one is running k8s then one could update the tag of a docker-image that is defined in the deployment.yaml and do a `kubectl up` again.
  
  
  ---
  
  