2

How to move Docker container from.Local system to AWs.I have configured docker in my local system . I need to move docker container from my local system to aws EC2 instance.

Siva Sai
  • 319
  • 2
  • 5
  • 21
  • 1
    Probably you want to run your container in the production in AWS. There are several actions you have to take into account while moving to the production. Below is the good description that might be helpful to you before going to production use case. http://blog.cloud66.com/9-crtitical-decisions-needed-to-run-docker-in-production/ – Janshair Khan Jan 21 '17 at 17:09
  • Hi janshair. But my docker container is in my local system. – Siva Sai Jan 21 '17 at 17:17
  • You can use docker hub, upload your docker container to docker hub and then in ec2 pull the image. – Hosar Jan 21 '17 at 18:38
  • @SivaSai, If you have one container and one host, then push it to a *Registry*, *ssh* into the machine in the AWS, run and expose the port from the container and finally access the container application in the browser. Following is my post but its for Azure, implement it at AWS the same way. :) http://www.kjanshair.com/docker/dockeronazure/ – Janshair Khan Jan 21 '17 at 20:23

1 Answers1

8

In a one time scenario you have these options:

A: To transfer your image:

  1. Save your image on your local machine:

    docker save my_image > my_image.tar

  2. Upload tar to your remote server:

    scp my_image.tar user@aws-machine:.

  3. Load image on your remote machine:

    ssh user@aws-machine

    docker load < my_image.tar

  4. Run a new container

    docker run my_image

B: To transfer your container:

  1. Export your container on your local machine:

    docker export my_container_id > my_container.tar

  2. Upload tar to your remote server:

    scp my_container.tar user@aws-machine:.

  3. Load tar as image on your remote machine:

    ssh user@aws-machine

    cat my_container | docker import - my-container-exported:latest

  4. Run a new container

    docker run my-container-exported:latest

To be prepared for later deployment improvements (like using CD/CI) you should consider option A. All necessary data for execution should be in the image and important data should be stored externally (volume mount, database, ..)

Jannik Weichert
  • 1,623
  • 16
  • 28
  • Can say that B did not work at all for me, as in the `cat my_container | docker import - my-container-exported:latest` ran but the run command then produced an error. After waiting for 900MB to upload a second time, A worked fine (thanks..) and the `docker load` command generated 15 layers maybe that simply needs to happen on the machine where it runs, am a beginner with this docker stuff.. – cardamom Jun 06 '17 at 15:01