Search code examples
dockerproduction-environment

What is the easiest way to export a Docker container to VM


I have Hbase docker container running in dev server. What is the best way to export it to production VM with all data inside.


Solution

  • With the command docker commit you can create a image from a container, then put the image on your resgistry, and in Production use the command docker run to run the container with the new image. The new image will have all data inside.

    Example:

    1. On dev, get the id of your by docker ps

      docker ps
      CONTAINER ID      IMAGE        COMMAND            CREATED        STATUS              PORTS                   NAMES
      ba8a9e9ecd1b      Hbase/ex1    "/sbin/my_init"    12 days ago    Up About a minute   0.0.0.0:80, 0.0.0.0:80  dev-c
      
    2. Create a new image from the container

      docker commit ba8a9e9ecd1b repo/new-image
      
    3. Push you new image to registry

      docker push repo/new-image
      
    4. Run the container in Production

      docker run -itd repo/new-image