Change data directory of Docker





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







7















How can I change the data directory of Docker where docker save the container (or where lxc save the container)?
I have in my server a ssd and a hard drive ant I want that the container will be save on the hard drive.
Thanks










share|improve this question





























    7















    How can I change the data directory of Docker where docker save the container (or where lxc save the container)?
    I have in my server a ssd and a hard drive ant I want that the container will be save on the hard drive.
    Thanks










    share|improve this question

























      7












      7








      7


      4






      How can I change the data directory of Docker where docker save the container (or where lxc save the container)?
      I have in my server a ssd and a hard drive ant I want that the container will be save on the hard drive.
      Thanks










      share|improve this question














      How can I change the data directory of Docker where docker save the container (or where lxc save the container)?
      I have in my server a ssd and a hard drive ant I want that the container will be save on the hard drive.
      Thanks







      server lxc docker






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 2 '15 at 18:21









      ssd_riderssd_rider

      1401214




      1401214






















          5 Answers
          5






          active

          oldest

          votes


















          10














          I believe that in this guide you'll have a good explanation.




          You can change Docker's storage base directory (where container and images go) using the -g option when starting the Docker daemon.



          Ubuntu/Debian: edit your /etc/default/docker file with the -g option: DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4 -g /mnt"



          Fedora/Centos: edit /etc/sysconfig/docker, and add the -g option in the other_args variable: ex. other_args="-g /var/lib/testdir". If there's more than one option, make sure you enclose them in " ". After a restart, (service docker restart) Docker should use the new directory.



          Using a symlink is another method to change image storage.



          Caution - These steps depend on your current /var/lib/docker being an actual directory (not a symlink to another location).



          1) Stop docker: service docker stop. Verify no docker process is running ps faux



          2) Double check docker really isn't running. Take a look at the current docker directory: ls /var/lib/docker/



          2b) Make a backup - tar -zcC /var/lib docker > /mnt/pd0/var_lib_docker-backup-$(date +%s).tar.gz



          3) Move the /var/lib/docker directory to your new partition: mv /var/lib/docker /mnt/pd0/docker



          4) Make a symlink: ln -s /mnt/pd0/docker /var/lib/docker



          5) Take a peek at the directory structure to make sure it looks like it did before the mv: ls /var/lib/docker/ (note the trailing slash to



          6) Start docker back up service docker start



          7) restart your containersresolve the symlink)







          share|improve this answer


























          • what is the reason for 4)? Is it needed? In my case, I would like to have docker files to be on a mounted RAID, and not on the boot partition.

            – Roman Mik
            Feb 27 '17 at 16:34



















          8














          In more recent Docker versions on Ubuntu you will edit /etc/default/daemon.json like so:



          {
          "data-root": "/new/location"
          }





          share|improve this answer































            1














            To change the data directory in docker it needs to be run with the option -g /my/data. In my /etc/default/docker I set:



            DOCKER_OPTS="-g /srv/docker"



            See also my notes here.



            To change the data directory in lxc I put in /etc/lxc/lxc.conf:



            lxc.lxcpath = /srv/lxc






            share|improve this answer































              1














              Upgrade to Docker 1.13.0.



              From the Release Notes:



              - New
              The storage location of the Linux volume can now be moved





              share|improve this answer































                0














                To expand on @MattK's answer:



                The Docker documentation on controlling the Docker daemon suggests that platform independent way to do this is:



                edit the /etc/docker/daemon.json file to contain the line



                {
                "data-root": "/mnt/docker-data",
                (...)
                }


                where /mnt/docker-data is the directory where you want the docker images and containers to live.



                Then



                sudo systemctl restart docker


                You can check whether it worked by running



                docker info


                and look for the contents of the line that start with Docker Root Dir:.



                See also https://stackoverflow.com/a/50217666/2209313 and https://unix.stackexchange.com/q/452368/36043.






                share|improve this answer








                New contributor




                Wandering Logic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





















                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "89"
                  };
                  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%2faskubuntu.com%2fquestions%2f631450%2fchange-data-directory-of-docker%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  10














                  I believe that in this guide you'll have a good explanation.




                  You can change Docker's storage base directory (where container and images go) using the -g option when starting the Docker daemon.



                  Ubuntu/Debian: edit your /etc/default/docker file with the -g option: DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4 -g /mnt"



                  Fedora/Centos: edit /etc/sysconfig/docker, and add the -g option in the other_args variable: ex. other_args="-g /var/lib/testdir". If there's more than one option, make sure you enclose them in " ". After a restart, (service docker restart) Docker should use the new directory.



                  Using a symlink is another method to change image storage.



                  Caution - These steps depend on your current /var/lib/docker being an actual directory (not a symlink to another location).



                  1) Stop docker: service docker stop. Verify no docker process is running ps faux



                  2) Double check docker really isn't running. Take a look at the current docker directory: ls /var/lib/docker/



                  2b) Make a backup - tar -zcC /var/lib docker > /mnt/pd0/var_lib_docker-backup-$(date +%s).tar.gz



                  3) Move the /var/lib/docker directory to your new partition: mv /var/lib/docker /mnt/pd0/docker



                  4) Make a symlink: ln -s /mnt/pd0/docker /var/lib/docker



                  5) Take a peek at the directory structure to make sure it looks like it did before the mv: ls /var/lib/docker/ (note the trailing slash to



                  6) Start docker back up service docker start



                  7) restart your containersresolve the symlink)







                  share|improve this answer


























                  • what is the reason for 4)? Is it needed? In my case, I would like to have docker files to be on a mounted RAID, and not on the boot partition.

                    – Roman Mik
                    Feb 27 '17 at 16:34
















                  10














                  I believe that in this guide you'll have a good explanation.




                  You can change Docker's storage base directory (where container and images go) using the -g option when starting the Docker daemon.



                  Ubuntu/Debian: edit your /etc/default/docker file with the -g option: DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4 -g /mnt"



                  Fedora/Centos: edit /etc/sysconfig/docker, and add the -g option in the other_args variable: ex. other_args="-g /var/lib/testdir". If there's more than one option, make sure you enclose them in " ". After a restart, (service docker restart) Docker should use the new directory.



                  Using a symlink is another method to change image storage.



                  Caution - These steps depend on your current /var/lib/docker being an actual directory (not a symlink to another location).



                  1) Stop docker: service docker stop. Verify no docker process is running ps faux



                  2) Double check docker really isn't running. Take a look at the current docker directory: ls /var/lib/docker/



                  2b) Make a backup - tar -zcC /var/lib docker > /mnt/pd0/var_lib_docker-backup-$(date +%s).tar.gz



                  3) Move the /var/lib/docker directory to your new partition: mv /var/lib/docker /mnt/pd0/docker



                  4) Make a symlink: ln -s /mnt/pd0/docker /var/lib/docker



                  5) Take a peek at the directory structure to make sure it looks like it did before the mv: ls /var/lib/docker/ (note the trailing slash to



                  6) Start docker back up service docker start



                  7) restart your containersresolve the symlink)







                  share|improve this answer


























                  • what is the reason for 4)? Is it needed? In my case, I would like to have docker files to be on a mounted RAID, and not on the boot partition.

                    – Roman Mik
                    Feb 27 '17 at 16:34














                  10












                  10








                  10







                  I believe that in this guide you'll have a good explanation.




                  You can change Docker's storage base directory (where container and images go) using the -g option when starting the Docker daemon.



                  Ubuntu/Debian: edit your /etc/default/docker file with the -g option: DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4 -g /mnt"



                  Fedora/Centos: edit /etc/sysconfig/docker, and add the -g option in the other_args variable: ex. other_args="-g /var/lib/testdir". If there's more than one option, make sure you enclose them in " ". After a restart, (service docker restart) Docker should use the new directory.



                  Using a symlink is another method to change image storage.



                  Caution - These steps depend on your current /var/lib/docker being an actual directory (not a symlink to another location).



                  1) Stop docker: service docker stop. Verify no docker process is running ps faux



                  2) Double check docker really isn't running. Take a look at the current docker directory: ls /var/lib/docker/



                  2b) Make a backup - tar -zcC /var/lib docker > /mnt/pd0/var_lib_docker-backup-$(date +%s).tar.gz



                  3) Move the /var/lib/docker directory to your new partition: mv /var/lib/docker /mnt/pd0/docker



                  4) Make a symlink: ln -s /mnt/pd0/docker /var/lib/docker



                  5) Take a peek at the directory structure to make sure it looks like it did before the mv: ls /var/lib/docker/ (note the trailing slash to



                  6) Start docker back up service docker start



                  7) restart your containersresolve the symlink)







                  share|improve this answer















                  I believe that in this guide you'll have a good explanation.




                  You can change Docker's storage base directory (where container and images go) using the -g option when starting the Docker daemon.



                  Ubuntu/Debian: edit your /etc/default/docker file with the -g option: DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4 -g /mnt"



                  Fedora/Centos: edit /etc/sysconfig/docker, and add the -g option in the other_args variable: ex. other_args="-g /var/lib/testdir". If there's more than one option, make sure you enclose them in " ". After a restart, (service docker restart) Docker should use the new directory.



                  Using a symlink is another method to change image storage.



                  Caution - These steps depend on your current /var/lib/docker being an actual directory (not a symlink to another location).



                  1) Stop docker: service docker stop. Verify no docker process is running ps faux



                  2) Double check docker really isn't running. Take a look at the current docker directory: ls /var/lib/docker/



                  2b) Make a backup - tar -zcC /var/lib docker > /mnt/pd0/var_lib_docker-backup-$(date +%s).tar.gz



                  3) Move the /var/lib/docker directory to your new partition: mv /var/lib/docker /mnt/pd0/docker



                  4) Make a symlink: ln -s /mnt/pd0/docker /var/lib/docker



                  5) Take a peek at the directory structure to make sure it looks like it did before the mv: ls /var/lib/docker/ (note the trailing slash to



                  6) Start docker back up service docker start



                  7) restart your containersresolve the symlink)








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Oct 16 '16 at 21:32

























                  answered Aug 20 '15 at 16:56









                  Conrado FonsecaConrado Fonseca

                  20125




                  20125













                  • what is the reason for 4)? Is it needed? In my case, I would like to have docker files to be on a mounted RAID, and not on the boot partition.

                    – Roman Mik
                    Feb 27 '17 at 16:34



















                  • what is the reason for 4)? Is it needed? In my case, I would like to have docker files to be on a mounted RAID, and not on the boot partition.

                    – Roman Mik
                    Feb 27 '17 at 16:34

















                  what is the reason for 4)? Is it needed? In my case, I would like to have docker files to be on a mounted RAID, and not on the boot partition.

                  – Roman Mik
                  Feb 27 '17 at 16:34





                  what is the reason for 4)? Is it needed? In my case, I would like to have docker files to be on a mounted RAID, and not on the boot partition.

                  – Roman Mik
                  Feb 27 '17 at 16:34













                  8














                  In more recent Docker versions on Ubuntu you will edit /etc/default/daemon.json like so:



                  {
                  "data-root": "/new/location"
                  }





                  share|improve this answer




























                    8














                    In more recent Docker versions on Ubuntu you will edit /etc/default/daemon.json like so:



                    {
                    "data-root": "/new/location"
                    }





                    share|improve this answer


























                      8












                      8








                      8







                      In more recent Docker versions on Ubuntu you will edit /etc/default/daemon.json like so:



                      {
                      "data-root": "/new/location"
                      }





                      share|improve this answer













                      In more recent Docker versions on Ubuntu you will edit /etc/default/daemon.json like so:



                      {
                      "data-root": "/new/location"
                      }






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 15 '18 at 20:08









                      MattKMattK

                      22123




                      22123























                          1














                          To change the data directory in docker it needs to be run with the option -g /my/data. In my /etc/default/docker I set:



                          DOCKER_OPTS="-g /srv/docker"



                          See also my notes here.



                          To change the data directory in lxc I put in /etc/lxc/lxc.conf:



                          lxc.lxcpath = /srv/lxc






                          share|improve this answer




























                            1














                            To change the data directory in docker it needs to be run with the option -g /my/data. In my /etc/default/docker I set:



                            DOCKER_OPTS="-g /srv/docker"



                            See also my notes here.



                            To change the data directory in lxc I put in /etc/lxc/lxc.conf:



                            lxc.lxcpath = /srv/lxc






                            share|improve this answer


























                              1












                              1








                              1







                              To change the data directory in docker it needs to be run with the option -g /my/data. In my /etc/default/docker I set:



                              DOCKER_OPTS="-g /srv/docker"



                              See also my notes here.



                              To change the data directory in lxc I put in /etc/lxc/lxc.conf:



                              lxc.lxcpath = /srv/lxc






                              share|improve this answer













                              To change the data directory in docker it needs to be run with the option -g /my/data. In my /etc/default/docker I set:



                              DOCKER_OPTS="-g /srv/docker"



                              See also my notes here.



                              To change the data directory in lxc I put in /etc/lxc/lxc.conf:



                              lxc.lxcpath = /srv/lxc







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jul 29 '15 at 15:22









                              Stuart CardallStuart Cardall

                              1214




                              1214























                                  1














                                  Upgrade to Docker 1.13.0.



                                  From the Release Notes:



                                  - New
                                  The storage location of the Linux volume can now be moved





                                  share|improve this answer




























                                    1














                                    Upgrade to Docker 1.13.0.



                                    From the Release Notes:



                                    - New
                                    The storage location of the Linux volume can now be moved





                                    share|improve this answer


























                                      1












                                      1








                                      1







                                      Upgrade to Docker 1.13.0.



                                      From the Release Notes:



                                      - New
                                      The storage location of the Linux volume can now be moved





                                      share|improve this answer













                                      Upgrade to Docker 1.13.0.



                                      From the Release Notes:



                                      - New
                                      The storage location of the Linux volume can now be moved






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jan 26 '17 at 14:55









                                      SnowcrashSnowcrash

                                      14115




                                      14115























                                          0














                                          To expand on @MattK's answer:



                                          The Docker documentation on controlling the Docker daemon suggests that platform independent way to do this is:



                                          edit the /etc/docker/daemon.json file to contain the line



                                          {
                                          "data-root": "/mnt/docker-data",
                                          (...)
                                          }


                                          where /mnt/docker-data is the directory where you want the docker images and containers to live.



                                          Then



                                          sudo systemctl restart docker


                                          You can check whether it worked by running



                                          docker info


                                          and look for the contents of the line that start with Docker Root Dir:.



                                          See also https://stackoverflow.com/a/50217666/2209313 and https://unix.stackexchange.com/q/452368/36043.






                                          share|improve this answer








                                          New contributor




                                          Wandering Logic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.

























                                            0














                                            To expand on @MattK's answer:



                                            The Docker documentation on controlling the Docker daemon suggests that platform independent way to do this is:



                                            edit the /etc/docker/daemon.json file to contain the line



                                            {
                                            "data-root": "/mnt/docker-data",
                                            (...)
                                            }


                                            where /mnt/docker-data is the directory where you want the docker images and containers to live.



                                            Then



                                            sudo systemctl restart docker


                                            You can check whether it worked by running



                                            docker info


                                            and look for the contents of the line that start with Docker Root Dir:.



                                            See also https://stackoverflow.com/a/50217666/2209313 and https://unix.stackexchange.com/q/452368/36043.






                                            share|improve this answer








                                            New contributor




                                            Wandering Logic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                            Check out our Code of Conduct.























                                              0












                                              0








                                              0







                                              To expand on @MattK's answer:



                                              The Docker documentation on controlling the Docker daemon suggests that platform independent way to do this is:



                                              edit the /etc/docker/daemon.json file to contain the line



                                              {
                                              "data-root": "/mnt/docker-data",
                                              (...)
                                              }


                                              where /mnt/docker-data is the directory where you want the docker images and containers to live.



                                              Then



                                              sudo systemctl restart docker


                                              You can check whether it worked by running



                                              docker info


                                              and look for the contents of the line that start with Docker Root Dir:.



                                              See also https://stackoverflow.com/a/50217666/2209313 and https://unix.stackexchange.com/q/452368/36043.






                                              share|improve this answer








                                              New contributor




                                              Wandering Logic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.










                                              To expand on @MattK's answer:



                                              The Docker documentation on controlling the Docker daemon suggests that platform independent way to do this is:



                                              edit the /etc/docker/daemon.json file to contain the line



                                              {
                                              "data-root": "/mnt/docker-data",
                                              (...)
                                              }


                                              where /mnt/docker-data is the directory where you want the docker images and containers to live.



                                              Then



                                              sudo systemctl restart docker


                                              You can check whether it worked by running



                                              docker info


                                              and look for the contents of the line that start with Docker Root Dir:.



                                              See also https://stackoverflow.com/a/50217666/2209313 and https://unix.stackexchange.com/q/452368/36043.







                                              share|improve this answer








                                              New contributor




                                              Wandering Logic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.









                                              share|improve this answer



                                              share|improve this answer






                                              New contributor




                                              Wandering Logic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.









                                              answered 6 hours ago









                                              Wandering LogicWandering Logic

                                              1012




                                              1012




                                              New contributor




                                              Wandering Logic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.





                                              New contributor





                                              Wandering Logic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.






                                              Wandering Logic is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                              Check out our Code of Conduct.






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Ask Ubuntu!


                                                  • 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%2faskubuntu.com%2fquestions%2f631450%2fchange-data-directory-of-docker%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

                                                  GameSpot

                                                  日野市

                                                  Tu-95轟炸機