Remote Docker access between Rocky Linux and Mac OS
On the Remote Linux:
Install docker on the targetted host. Please follow the official documentation to do so.
sudo dnf install rsync -y
sudo mkdir /opt/projects
sudo chown tgingras:tgingras /opt/projects
sudo chmod 0774 /opt/projects
On the local Mac:
Prepare the SSH Access:
ssh-keygen
ssh-copy-id -i /Users/tgingras/.ssh/remote_rsa [email protected]
ssh -i ~/.ssh/remote_rsa [email protected]
cat > /Users/tgingras/.ssh/config <<EOF
Host remote
HostName 192.168.2.19
user tgingras
IdentityFile ~/.ssh/remote_rsa
EOF
Test the SSH Access:
ssh remote
Script to sync the local files to the remote host:
cat > ~/.sync.sh <<EOF
#!/bin/bash
set -e
input=""
if [ ! -d ".git/" ]; then
echo ".git/ not found, are you sure you want to proceed (y/N)?"
read input
case \$input in
y|Y ) echo -e "Syncing...\n";;
n|N ) exit;;
* ) exit;;
esac
fi
projectName=\$(pwd | rev | cut -d '/' -f1 | rev)
rsync -avzh --exclude 'node_modules/' --exclude '.git/' --delete ./ remote:/opt/projects/\${projectName}/
EOF
chmod +x ~/.sync.sh
echo -e "\nalias yat-sync='bash ~/.sync.sh'\n" >> ~/.zshrc
source ~/.zshrc
Install Docker CLI and target the remote Linux Docker:
You can use macport, homebrew or whatever.
sudo port install docker
export DOCKER_HOST=ssh://remote
docker ps -a
Using this approach, you will be able to sync your local changes to the remote server, in other words, use volumes. Also you will be able to use the power of docker on your remote machine.
This way you can either use docker locally or remotely without worrying with files, directories or git.