user977828
user977828

Reputation: 7679

change PATH for building docker image

This command sudo docker build -t mydocker . build the image in /var/lib/docker. Is there a way to change it to another folder e.g. /home/user1/docker?

Upvotes: 4

Views: 4970

Answers (2)

MadukaJ
MadukaJ

Reputation: 761

For the new version of Docker, you have to change daemon.json.

 sudo nano /etc/docker/daemon.json

then add the path to the deamon JSON (In my case path is '/media/newhd/containers/')

{"data-root":"/media/newhd/containers/"}

After this restart the docker...

Upvotes: 3

Rico
Rico

Reputation: 61521

You have to restart the docker daemon with the -g option.

docker -d -g /home/user1/docker

or

docker -d --graph="/home/user1/docker" 

Keep in mind that once you do this, all your images for that docker daemon instance will get stored on /home/user1/docker

And also that generally the Docker daemon runs a root. So it's probably better to specify a directory owned by root

Upvotes: 2

Related Questions