#Docker on GCE see:
##Instantiate a docker VM
- install gcutil/gcloud (see here: https://developers.google.com/compute/docs/gcutil/)
- gcloud auth login
- goto the page and auth...
- Either install on a fresh VM,
- or use the pre-installed public image:
The following steps are a an example setup, and give a flavour of the steps to go through:
e.g. VM called dockerbox
gcloud compute instances create dockerbox \
--image container-vm-v20140710 \
--image-project google-containers \
--zone europe-west1-b \
--machine-type f1-micro
Add a additional disk, here a 500GB, (will eventually house /var/lib/docker):
gcutil --project=<PROJECT-ID> adddisk container-vol --size_gb=500 --zone=europe-west1-b --disk_type=pd-standard
Attach it to the dockerbox VM
gcutil --project=secure-electron-631 attachdisk --zone=europe-west1-b --disk=container-vol,mode=read_write dockerbox
format the disk..on the instance..If your disk is listed when you run ls -l /dev/disk/by-id/*
will show you the attached disks:
sudo /usr/share/google/safe_format_and_mount -m "mkfs.ext4 -F" /dev/disk/by-id/scsi-0Google_PersistentDisk_container-vol /media/container-vol
create a mount point & add to /etc/fstab
(e.g. /dev/sdb
in this case):
sudo mkdir /media/container-vol
sudo echo "/dev/sdb /media/container-vol ext4 defaults 1 1" sudo cat >> /etc/fstab
now mount:
sudo mount -a
create a mountpoint for the docker runtime dir & bind mount /var/lib/docker
in your new 500gb disk:
sudo mkdir /media/container-vol/var/lib/docker
sudo cp /var/lib/docker /media/container-vol/var/lib/docker
sudo echo "/media/container-vol/var/lib/docker /var/lib/docker bind defaults,bind 0 0" >> /etc/fstab
##Moving the /var/lib/docker
to the new disk
THe path to use as the root of the Docker runtime is /var/lib/docker
. We want to keep the boot disk small (only 10GB), but the /var/lib/docker
will house all our containers, filesystems, images etc.. in short it will likely grow substantially. So we need to move it to the 500GB disk.
First stop the docker daemon:
docker ps -q | xargs docker kill
service docker stop
if it exists:
cd /var/lib/docker/devicemapper/mnt
umount ./*
Move the docker dir to the new disk:
dest='/media/container-vol/var/lib/docker'
mv /var/lib/docker $dest
Connect the location
While you could link ln -s $dest/docker /var/lib/docker
, it is better to use a bind mount see below.
Bind mount:
sudo mount -o bind /media/container-vol/var/lib/docker/ /var/lib/docker
you can also put in the fstab incase you re-start the box then it will still be mounted:
/media/container-vol/var/lib/docker/ /var/lib/docker bind defaults,bind 0 0
NOTE: if you are using a link be mindful that the device filesystem you are moving the /var/lib/docker dir supports hard and soft links! Note VirtualBox FS (vboxfs) doesn't!
modify defaults options in docker in /etc/defaults/docker
so it docker daemon knows where to find the root of the docker runtime "-g option":
DOCKER_OPTS="-H 127.0.0.1:4243 -H unix:///var/run/docker.sock -r=false -g $(readlink -f /var/lib/docker)"
Lastly, restart the docker daemon… (you might need to do it a couple of times before it will say 'ok'):
sudo /etc/init.d/docker restart