Save the current state of docker image and export to another server












0














I am new to docker and containers.
I followed the below steps to migrate my postgres database running on a docker container:



docker save -o <path for generated tar file> <image name>
scp root@192.10.1.5:/images/gpdb.tar root@192.10.2.5:/images


In the destination server (192.10.2.5):



docker load -i /images/gpdb.tar


But, when I login to the docker image, the database is not there.
How do I save the docker image with all database tables and data.










share|improve this question



























    0














    I am new to docker and containers.
    I followed the below steps to migrate my postgres database running on a docker container:



    docker save -o <path for generated tar file> <image name>
    scp root@192.10.1.5:/images/gpdb.tar root@192.10.2.5:/images


    In the destination server (192.10.2.5):



    docker load -i /images/gpdb.tar


    But, when I login to the docker image, the database is not there.
    How do I save the docker image with all database tables and data.










    share|improve this question

























      0












      0








      0







      I am new to docker and containers.
      I followed the below steps to migrate my postgres database running on a docker container:



      docker save -o <path for generated tar file> <image name>
      scp root@192.10.1.5:/images/gpdb.tar root@192.10.2.5:/images


      In the destination server (192.10.2.5):



      docker load -i /images/gpdb.tar


      But, when I login to the docker image, the database is not there.
      How do I save the docker image with all database tables and data.










      share|improve this question













      I am new to docker and containers.
      I followed the below steps to migrate my postgres database running on a docker container:



      docker save -o <path for generated tar file> <image name>
      scp root@192.10.1.5:/images/gpdb.tar root@192.10.2.5:/images


      In the destination server (192.10.2.5):



      docker load -i /images/gpdb.tar


      But, when I login to the docker image, the database is not there.
      How do I save the docker image with all database tables and data.







      docker






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 at 7:20









      Tammy

      562926




      562926
























          4 Answers
          4






          active

          oldest

          votes


















          0














          There's no database because the docker save and docker commit commands don't save the container volumes...



          Here's a script to do just that:



          https://github.com/ricardobranco777/docker-volumes.sh



          # Stop the container 
          docker stop $CONTAINER
          # Create a new image
          docker commit $CONTAINER $CONTAINER
          # Save and load image to another host
          docker save $CONTAINER | ssh $USER@$HOST docker load

          # Save the volumes (use ".tar.gz" if you want compression)
          docker-volumes.sh $CONTAINER save $CONTAINER-volumes.tar

          # Copy image and volumes to another host
          scp $CONTAINER.tar $CONTAINER-volumes.tar $USER@$HOST:

          ### On the other host:

          # Create container with the same options used by the previous container
          docker create --name $CONTAINER [<PREVIOUS CONTAINER OPTIONS>] $CONTAINER

          # Load the volumes
          docker-volumes.sh $CONTAINER load $CONTAINER-volumes.tar

          # Start container
          docker start $CONTAINER





          share|improve this answer





















          • Thanks. Now I have a new question that how the container maintains its current state if it does not alter the image. But, it will be a reading task for me.
            – Tammy
            Nov 13 at 10:48






          • 1




            The docker commit command save any changes made to the container in directories that are not volumes. The script saves and loads the volumes.
            – Ricardo Branco
            Nov 13 at 10:53



















          0














          Your container was based on image when start, but after start, all changes will not affect image.



          So all your changes including database if made on the runtime of container need to be commit to form a new docker image before save.



          Something like follows, see here



          docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]


          Then save the new image to tar, and do what you wanted.






          share|improve this answer





















          • This doesn't save the container volumes.
            – Ricardo Branco
            Nov 13 at 10:32










          • you are true if op has volume
            – lagom
            Nov 13 at 10:37










          • Any database container will have volumes...
            – Ricardo Branco
            Nov 13 at 10:51










          • maybe k8s or --link?
            – lagom
            Nov 13 at 10:54










          • k8s or --link is not the case here.
            – Ricardo Branco
            Nov 13 at 10:55



















          0














          commit the current state to the image



          docker commit currentcontainer newimage


          save image as a tar file



          docker save newimage > /tmp/newimage.tar


          load the container from the image



          docker load < /tmp/newimage.tar





          share|improve this answer





























            0














            Trying to move a container like this is not a best practice. It may take some setup to get your container into the right state, though.



            The important detail is that all data that could change and needs to be persisted needs to be stored outside the container. While Docker endorses named volumes for this, using a native filesystem path is IME easier to maintain and move around. You need to know where inside the container the data goes (it's usually well-documented) but then you can run commands like



            docker run -v /data/mysql:/var/lib/mysql/data ... mysql


            Now you can do whatever you want with the container, even docker rm it, but just so long as /data/mysql on your host is intact your data is fine. That also means you can use an ordinary scp to copy the data to some other host and docker run the same container there, which is the more typical migration path.



            If you're building and running custom images, there are a couple of things to check:




            • You really should be using some sort of Docker registry, whether that's Docker Hub, something your cloud provider offers, something third-party, or something self-hosted. docker save to move images around is a last resort that's rarely needed.


            • The images themselves should be built from Dockerfiles and, like the rest of your application, be checked into source control. Ideally you have an automated build system (continuous integration) running docker build && docker push for you. Never use docker commit or docker export: they are a recipe for getting different versions of software on different systems and not remembering how you got there.


            • Your application should minimize the amount of data it stores locally. Best case is to store everything in an external database, and then you can just point at the database; if local file storage is really unavoidable try to contain it all in a single directory that's not within your application's source tree.


            • Locally you should be freely able to docker stop; docker rm; docker run the same container and not lose data. Test this before you need to do a cross-host migration.



            If you can structure your application so that all of its data is in an external database, consider running the database on a dedicated host with extremely good backup procedures. If you've done everything up to here, you can have a massive coordinated hard disk failure and lose all of your Docker hosts, and not actually have lost anything (because you can docker build the images from source again, and docker run the containers, and the data is off-host).






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275779%2fsave-the-current-state-of-docker-image-and-export-to-another-server%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              There's no database because the docker save and docker commit commands don't save the container volumes...



              Here's a script to do just that:



              https://github.com/ricardobranco777/docker-volumes.sh



              # Stop the container 
              docker stop $CONTAINER
              # Create a new image
              docker commit $CONTAINER $CONTAINER
              # Save and load image to another host
              docker save $CONTAINER | ssh $USER@$HOST docker load

              # Save the volumes (use ".tar.gz" if you want compression)
              docker-volumes.sh $CONTAINER save $CONTAINER-volumes.tar

              # Copy image and volumes to another host
              scp $CONTAINER.tar $CONTAINER-volumes.tar $USER@$HOST:

              ### On the other host:

              # Create container with the same options used by the previous container
              docker create --name $CONTAINER [<PREVIOUS CONTAINER OPTIONS>] $CONTAINER

              # Load the volumes
              docker-volumes.sh $CONTAINER load $CONTAINER-volumes.tar

              # Start container
              docker start $CONTAINER





              share|improve this answer





















              • Thanks. Now I have a new question that how the container maintains its current state if it does not alter the image. But, it will be a reading task for me.
                – Tammy
                Nov 13 at 10:48






              • 1




                The docker commit command save any changes made to the container in directories that are not volumes. The script saves and loads the volumes.
                – Ricardo Branco
                Nov 13 at 10:53
















              0














              There's no database because the docker save and docker commit commands don't save the container volumes...



              Here's a script to do just that:



              https://github.com/ricardobranco777/docker-volumes.sh



              # Stop the container 
              docker stop $CONTAINER
              # Create a new image
              docker commit $CONTAINER $CONTAINER
              # Save and load image to another host
              docker save $CONTAINER | ssh $USER@$HOST docker load

              # Save the volumes (use ".tar.gz" if you want compression)
              docker-volumes.sh $CONTAINER save $CONTAINER-volumes.tar

              # Copy image and volumes to another host
              scp $CONTAINER.tar $CONTAINER-volumes.tar $USER@$HOST:

              ### On the other host:

              # Create container with the same options used by the previous container
              docker create --name $CONTAINER [<PREVIOUS CONTAINER OPTIONS>] $CONTAINER

              # Load the volumes
              docker-volumes.sh $CONTAINER load $CONTAINER-volumes.tar

              # Start container
              docker start $CONTAINER





              share|improve this answer





















              • Thanks. Now I have a new question that how the container maintains its current state if it does not alter the image. But, it will be a reading task for me.
                – Tammy
                Nov 13 at 10:48






              • 1




                The docker commit command save any changes made to the container in directories that are not volumes. The script saves and loads the volumes.
                – Ricardo Branco
                Nov 13 at 10:53














              0












              0








              0






              There's no database because the docker save and docker commit commands don't save the container volumes...



              Here's a script to do just that:



              https://github.com/ricardobranco777/docker-volumes.sh



              # Stop the container 
              docker stop $CONTAINER
              # Create a new image
              docker commit $CONTAINER $CONTAINER
              # Save and load image to another host
              docker save $CONTAINER | ssh $USER@$HOST docker load

              # Save the volumes (use ".tar.gz" if you want compression)
              docker-volumes.sh $CONTAINER save $CONTAINER-volumes.tar

              # Copy image and volumes to another host
              scp $CONTAINER.tar $CONTAINER-volumes.tar $USER@$HOST:

              ### On the other host:

              # Create container with the same options used by the previous container
              docker create --name $CONTAINER [<PREVIOUS CONTAINER OPTIONS>] $CONTAINER

              # Load the volumes
              docker-volumes.sh $CONTAINER load $CONTAINER-volumes.tar

              # Start container
              docker start $CONTAINER





              share|improve this answer












              There's no database because the docker save and docker commit commands don't save the container volumes...



              Here's a script to do just that:



              https://github.com/ricardobranco777/docker-volumes.sh



              # Stop the container 
              docker stop $CONTAINER
              # Create a new image
              docker commit $CONTAINER $CONTAINER
              # Save and load image to another host
              docker save $CONTAINER | ssh $USER@$HOST docker load

              # Save the volumes (use ".tar.gz" if you want compression)
              docker-volumes.sh $CONTAINER save $CONTAINER-volumes.tar

              # Copy image and volumes to another host
              scp $CONTAINER.tar $CONTAINER-volumes.tar $USER@$HOST:

              ### On the other host:

              # Create container with the same options used by the previous container
              docker create --name $CONTAINER [<PREVIOUS CONTAINER OPTIONS>] $CONTAINER

              # Load the volumes
              docker-volumes.sh $CONTAINER load $CONTAINER-volumes.tar

              # Start container
              docker start $CONTAINER






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 13 at 9:26









              Ricardo Branco

              3,2121614




              3,2121614












              • Thanks. Now I have a new question that how the container maintains its current state if it does not alter the image. But, it will be a reading task for me.
                – Tammy
                Nov 13 at 10:48






              • 1




                The docker commit command save any changes made to the container in directories that are not volumes. The script saves and loads the volumes.
                – Ricardo Branco
                Nov 13 at 10:53


















              • Thanks. Now I have a new question that how the container maintains its current state if it does not alter the image. But, it will be a reading task for me.
                – Tammy
                Nov 13 at 10:48






              • 1




                The docker commit command save any changes made to the container in directories that are not volumes. The script saves and loads the volumes.
                – Ricardo Branco
                Nov 13 at 10:53
















              Thanks. Now I have a new question that how the container maintains its current state if it does not alter the image. But, it will be a reading task for me.
              – Tammy
              Nov 13 at 10:48




              Thanks. Now I have a new question that how the container maintains its current state if it does not alter the image. But, it will be a reading task for me.
              – Tammy
              Nov 13 at 10:48




              1




              1




              The docker commit command save any changes made to the container in directories that are not volumes. The script saves and loads the volumes.
              – Ricardo Branco
              Nov 13 at 10:53




              The docker commit command save any changes made to the container in directories that are not volumes. The script saves and loads the volumes.
              – Ricardo Branco
              Nov 13 at 10:53













              0














              Your container was based on image when start, but after start, all changes will not affect image.



              So all your changes including database if made on the runtime of container need to be commit to form a new docker image before save.



              Something like follows, see here



              docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]


              Then save the new image to tar, and do what you wanted.






              share|improve this answer





















              • This doesn't save the container volumes.
                – Ricardo Branco
                Nov 13 at 10:32










              • you are true if op has volume
                – lagom
                Nov 13 at 10:37










              • Any database container will have volumes...
                – Ricardo Branco
                Nov 13 at 10:51










              • maybe k8s or --link?
                – lagom
                Nov 13 at 10:54










              • k8s or --link is not the case here.
                – Ricardo Branco
                Nov 13 at 10:55
















              0














              Your container was based on image when start, but after start, all changes will not affect image.



              So all your changes including database if made on the runtime of container need to be commit to form a new docker image before save.



              Something like follows, see here



              docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]


              Then save the new image to tar, and do what you wanted.






              share|improve this answer





















              • This doesn't save the container volumes.
                – Ricardo Branco
                Nov 13 at 10:32










              • you are true if op has volume
                – lagom
                Nov 13 at 10:37










              • Any database container will have volumes...
                – Ricardo Branco
                Nov 13 at 10:51










              • maybe k8s or --link?
                – lagom
                Nov 13 at 10:54










              • k8s or --link is not the case here.
                – Ricardo Branco
                Nov 13 at 10:55














              0












              0








              0






              Your container was based on image when start, but after start, all changes will not affect image.



              So all your changes including database if made on the runtime of container need to be commit to form a new docker image before save.



              Something like follows, see here



              docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]


              Then save the new image to tar, and do what you wanted.






              share|improve this answer












              Your container was based on image when start, but after start, all changes will not affect image.



              So all your changes including database if made on the runtime of container need to be commit to form a new docker image before save.



              Something like follows, see here



              docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]


              Then save the new image to tar, and do what you wanted.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 13 at 7:49









              lagom

              3,42671737




              3,42671737












              • This doesn't save the container volumes.
                – Ricardo Branco
                Nov 13 at 10:32










              • you are true if op has volume
                – lagom
                Nov 13 at 10:37










              • Any database container will have volumes...
                – Ricardo Branco
                Nov 13 at 10:51










              • maybe k8s or --link?
                – lagom
                Nov 13 at 10:54










              • k8s or --link is not the case here.
                – Ricardo Branco
                Nov 13 at 10:55


















              • This doesn't save the container volumes.
                – Ricardo Branco
                Nov 13 at 10:32










              • you are true if op has volume
                – lagom
                Nov 13 at 10:37










              • Any database container will have volumes...
                – Ricardo Branco
                Nov 13 at 10:51










              • maybe k8s or --link?
                – lagom
                Nov 13 at 10:54










              • k8s or --link is not the case here.
                – Ricardo Branco
                Nov 13 at 10:55
















              This doesn't save the container volumes.
              – Ricardo Branco
              Nov 13 at 10:32




              This doesn't save the container volumes.
              – Ricardo Branco
              Nov 13 at 10:32












              you are true if op has volume
              – lagom
              Nov 13 at 10:37




              you are true if op has volume
              – lagom
              Nov 13 at 10:37












              Any database container will have volumes...
              – Ricardo Branco
              Nov 13 at 10:51




              Any database container will have volumes...
              – Ricardo Branco
              Nov 13 at 10:51












              maybe k8s or --link?
              – lagom
              Nov 13 at 10:54




              maybe k8s or --link?
              – lagom
              Nov 13 at 10:54












              k8s or --link is not the case here.
              – Ricardo Branco
              Nov 13 at 10:55




              k8s or --link is not the case here.
              – Ricardo Branco
              Nov 13 at 10:55











              0














              commit the current state to the image



              docker commit currentcontainer newimage


              save image as a tar file



              docker save newimage > /tmp/newimage.tar


              load the container from the image



              docker load < /tmp/newimage.tar





              share|improve this answer


























                0














                commit the current state to the image



                docker commit currentcontainer newimage


                save image as a tar file



                docker save newimage > /tmp/newimage.tar


                load the container from the image



                docker load < /tmp/newimage.tar





                share|improve this answer
























                  0












                  0








                  0






                  commit the current state to the image



                  docker commit currentcontainer newimage


                  save image as a tar file



                  docker save newimage > /tmp/newimage.tar


                  load the container from the image



                  docker load < /tmp/newimage.tar





                  share|improve this answer












                  commit the current state to the image



                  docker commit currentcontainer newimage


                  save image as a tar file



                  docker save newimage > /tmp/newimage.tar


                  load the container from the image



                  docker load < /tmp/newimage.tar






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 at 9:20









                  marekmuratow

                  12910




                  12910























                      0














                      Trying to move a container like this is not a best practice. It may take some setup to get your container into the right state, though.



                      The important detail is that all data that could change and needs to be persisted needs to be stored outside the container. While Docker endorses named volumes for this, using a native filesystem path is IME easier to maintain and move around. You need to know where inside the container the data goes (it's usually well-documented) but then you can run commands like



                      docker run -v /data/mysql:/var/lib/mysql/data ... mysql


                      Now you can do whatever you want with the container, even docker rm it, but just so long as /data/mysql on your host is intact your data is fine. That also means you can use an ordinary scp to copy the data to some other host and docker run the same container there, which is the more typical migration path.



                      If you're building and running custom images, there are a couple of things to check:




                      • You really should be using some sort of Docker registry, whether that's Docker Hub, something your cloud provider offers, something third-party, or something self-hosted. docker save to move images around is a last resort that's rarely needed.


                      • The images themselves should be built from Dockerfiles and, like the rest of your application, be checked into source control. Ideally you have an automated build system (continuous integration) running docker build && docker push for you. Never use docker commit or docker export: they are a recipe for getting different versions of software on different systems and not remembering how you got there.


                      • Your application should minimize the amount of data it stores locally. Best case is to store everything in an external database, and then you can just point at the database; if local file storage is really unavoidable try to contain it all in a single directory that's not within your application's source tree.


                      • Locally you should be freely able to docker stop; docker rm; docker run the same container and not lose data. Test this before you need to do a cross-host migration.



                      If you can structure your application so that all of its data is in an external database, consider running the database on a dedicated host with extremely good backup procedures. If you've done everything up to here, you can have a massive coordinated hard disk failure and lose all of your Docker hosts, and not actually have lost anything (because you can docker build the images from source again, and docker run the containers, and the data is off-host).






                      share|improve this answer


























                        0














                        Trying to move a container like this is not a best practice. It may take some setup to get your container into the right state, though.



                        The important detail is that all data that could change and needs to be persisted needs to be stored outside the container. While Docker endorses named volumes for this, using a native filesystem path is IME easier to maintain and move around. You need to know where inside the container the data goes (it's usually well-documented) but then you can run commands like



                        docker run -v /data/mysql:/var/lib/mysql/data ... mysql


                        Now you can do whatever you want with the container, even docker rm it, but just so long as /data/mysql on your host is intact your data is fine. That also means you can use an ordinary scp to copy the data to some other host and docker run the same container there, which is the more typical migration path.



                        If you're building and running custom images, there are a couple of things to check:




                        • You really should be using some sort of Docker registry, whether that's Docker Hub, something your cloud provider offers, something third-party, or something self-hosted. docker save to move images around is a last resort that's rarely needed.


                        • The images themselves should be built from Dockerfiles and, like the rest of your application, be checked into source control. Ideally you have an automated build system (continuous integration) running docker build && docker push for you. Never use docker commit or docker export: they are a recipe for getting different versions of software on different systems and not remembering how you got there.


                        • Your application should minimize the amount of data it stores locally. Best case is to store everything in an external database, and then you can just point at the database; if local file storage is really unavoidable try to contain it all in a single directory that's not within your application's source tree.


                        • Locally you should be freely able to docker stop; docker rm; docker run the same container and not lose data. Test this before you need to do a cross-host migration.



                        If you can structure your application so that all of its data is in an external database, consider running the database on a dedicated host with extremely good backup procedures. If you've done everything up to here, you can have a massive coordinated hard disk failure and lose all of your Docker hosts, and not actually have lost anything (because you can docker build the images from source again, and docker run the containers, and the data is off-host).






                        share|improve this answer
























                          0












                          0








                          0






                          Trying to move a container like this is not a best practice. It may take some setup to get your container into the right state, though.



                          The important detail is that all data that could change and needs to be persisted needs to be stored outside the container. While Docker endorses named volumes for this, using a native filesystem path is IME easier to maintain and move around. You need to know where inside the container the data goes (it's usually well-documented) but then you can run commands like



                          docker run -v /data/mysql:/var/lib/mysql/data ... mysql


                          Now you can do whatever you want with the container, even docker rm it, but just so long as /data/mysql on your host is intact your data is fine. That also means you can use an ordinary scp to copy the data to some other host and docker run the same container there, which is the more typical migration path.



                          If you're building and running custom images, there are a couple of things to check:




                          • You really should be using some sort of Docker registry, whether that's Docker Hub, something your cloud provider offers, something third-party, or something self-hosted. docker save to move images around is a last resort that's rarely needed.


                          • The images themselves should be built from Dockerfiles and, like the rest of your application, be checked into source control. Ideally you have an automated build system (continuous integration) running docker build && docker push for you. Never use docker commit or docker export: they are a recipe for getting different versions of software on different systems and not remembering how you got there.


                          • Your application should minimize the amount of data it stores locally. Best case is to store everything in an external database, and then you can just point at the database; if local file storage is really unavoidable try to contain it all in a single directory that's not within your application's source tree.


                          • Locally you should be freely able to docker stop; docker rm; docker run the same container and not lose data. Test this before you need to do a cross-host migration.



                          If you can structure your application so that all of its data is in an external database, consider running the database on a dedicated host with extremely good backup procedures. If you've done everything up to here, you can have a massive coordinated hard disk failure and lose all of your Docker hosts, and not actually have lost anything (because you can docker build the images from source again, and docker run the containers, and the data is off-host).






                          share|improve this answer












                          Trying to move a container like this is not a best practice. It may take some setup to get your container into the right state, though.



                          The important detail is that all data that could change and needs to be persisted needs to be stored outside the container. While Docker endorses named volumes for this, using a native filesystem path is IME easier to maintain and move around. You need to know where inside the container the data goes (it's usually well-documented) but then you can run commands like



                          docker run -v /data/mysql:/var/lib/mysql/data ... mysql


                          Now you can do whatever you want with the container, even docker rm it, but just so long as /data/mysql on your host is intact your data is fine. That also means you can use an ordinary scp to copy the data to some other host and docker run the same container there, which is the more typical migration path.



                          If you're building and running custom images, there are a couple of things to check:




                          • You really should be using some sort of Docker registry, whether that's Docker Hub, something your cloud provider offers, something third-party, or something self-hosted. docker save to move images around is a last resort that's rarely needed.


                          • The images themselves should be built from Dockerfiles and, like the rest of your application, be checked into source control. Ideally you have an automated build system (continuous integration) running docker build && docker push for you. Never use docker commit or docker export: they are a recipe for getting different versions of software on different systems and not remembering how you got there.


                          • Your application should minimize the amount of data it stores locally. Best case is to store everything in an external database, and then you can just point at the database; if local file storage is really unavoidable try to contain it all in a single directory that's not within your application's source tree.


                          • Locally you should be freely able to docker stop; docker rm; docker run the same container and not lose data. Test this before you need to do a cross-host migration.



                          If you can structure your application so that all of its data is in an external database, consider running the database on a dedicated host with extremely good backup procedures. If you've done everything up to here, you can have a massive coordinated hard disk failure and lose all of your Docker hosts, and not actually have lost anything (because you can docker build the images from source again, and docker run the containers, and the data is off-host).







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 13 at 12:07









                          David Maze

                          10.1k2921




                          10.1k2921






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275779%2fsave-the-current-state-of-docker-image-and-export-to-another-server%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              鏡平學校

                              ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                              Why https connections are so slow when debugging (stepping over) in Java?