First, edit the settings.json file for VSCode. For Linux, do the following:

nano $HOME/Library/Application Support/Code/User/settings.json

Add the following line:

"docker.host":"ssh://username@ip-address"

The equivalent file in macOS can be found at:

$HOME/Library/Application Support/Code/User/settings.json

Local Docker settings

Now, to point docker at your remote machine, do the following.

docker context create machine-name --docker "host=ssh://username@ip-address"

Finally open up a new terminal, switch your docker context and start a container.

docker context use machine-name
docker start container_name

If everything went well, the left hand panel of VSCode (assuming the Docker extension is installed) should reflect the containers, images and volumes of the remote machine. You should now be able to attach to any running containers within VSCode in a new tab.

https://code.visualstudio.com/remote/advancedcontainers/develop-remote-host
https://code.visualstudio.com/docs/getstarted/settings
https://docs.docker.com/engine/context/working-with-contexts/