Skip to content

Instantly share code, notes, and snippets.

@zackexplosion
Created November 16, 2021 01:54
Show Gist options
  • Save zackexplosion/7af679815d6bc8506c437dc7bc022837 to your computer and use it in GitHub Desktop.
Save zackexplosion/7af679815d6bc8506c437dc7bc022837 to your computer and use it in GitHub Desktop.
docker build and deploy to nas
IMAGE_NAME=your-image-name
[email protected]
ARCHIVE_FILE_NAME=archive.tar
REMOTE_PATH=/a/remote/path
REMOTE_PORT=22
PORTMAP=1111:1111
rm $ARCHIVE_FILE_NAME
docker rmi $IMAGE_NAME
docker build . -t $IMAGE_NAME
docker save $IMAGE_NAME > $ARCHIVE_FILE_NAME
scp -P $REMOTE_PORT $ARCHIVE_FILE_NAME $NAS_URI:$REMOTE_PATH
set -x;
ssh -p $REMOTE_PORT $NAS_URI "/usr/local/bin/docker rm \$(/usr/local/bin/docker stop \$(/usr/local/bin/docker ps -a -q --filter ancestor=$IMAGE_NAME))"
set +x;
ssh -p $REMOTE_PORT $NAS_URI "/usr/local/bin/docker rmi $IMAGE_NAME"
ssh -p $REMOTE_PORT $NAS_URI "/usr/local/bin/docker load < $REMOTE_PATH/$ARCHIVE_FILE_NAME"
ssh -p $REMOTE_PORT $NAS_URI "/usr/local/bin/docker run -d -p $PORTMAP $IMAGE_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment