botbotbot 's blog

Add existed Docker host to docker-machine

Generic Driver - Create machines using an existing VM/Host with SSH

$ docker-machine create --driver generic \
    --generic-ip-address $host_ip \
    --generic-ssh-user $host_user \
    $machine_name

How to mount local volumes in docker machine

  • you can’t mount local volumes to remote server but you can upload your files with scp or rsync

  • docker-compose will mount file with the same path in both client and remote server, you can check you path $ pwd .

  • docker-machine scp

# download
$ docker-machine scp $machine:$src $dest

# upload
$ docker-machine scp $src $machine:$dest
# sync and delete file remote that not existed on local
rsync -rvzahe 'docker-machine ssh $machine' --delete --progress $src :$dest

# ignore .git directory
rsync -rvzahe 'docker-machine ssh $machine' --delete --progress --exclude='.git' $src :$dest"
# alias

export machine=digitalocean
# rsync for mount volume on remote docker host

# sync
alias dsync="rsync -rvzahe 'docker-machine ssh \$machine' --delete --progress --exclude='.git' . :\$PWD"

# remove file on server !!! danger
alias dclean="docker-machine ssh \$machine \"cd \$PWD && rm -r *\""

# need confirm before delete
alias dclean="echo \"cd $PWD && rm -r *\" | xargs -p docker-machine ssh \$machine"

# list dir on remote host
alias dlist="docker-machine ssh \$machine \"cd \$PWD && ls\""

References: