Question

VSCode remote Docker

I’d like to use this droplet as remote Docker server for VSCode development, I have Windows 11 with WSL2. If it is easy, I’d like next level - set up Windows Docker Desktop pointed to your(my) server


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
October 25, 2024

Heya,

By default, Docker only listens to local connections for security. You’ll need to configure it to accept remote connections.

  • Edit the Docker Daemon Configuration: Connect to your DigitalOcean droplet via SSH and Open the Docker daemon configuration file:
sudo nano /etc/docker/daemon.json

Add the following configuration, replacing YOUR_IP with your droplet’s IP address:

{
  "hosts": ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2376"],
  "tls": true,
  "tlsverify": true,
  "tlscacert": "/etc/docker/certs/ca.pem",
  "tlscert": "/etc/docker/certs/server-cert.pem",
  "tlskey": "/etc/docker/certs/server-key.pem"
}
    • hosts: Tells Docker to listen on TCP port 2376.
    • tls and tlsverify: Enable TLS encryption and verification to secure the connection.
  • Create and Install TLS Certificates: You’ll need to generate TLS certificates to securely connect to Docker remotely.

    On the droplet:

mkdir -p /etc/docker/certs
cd /etc/docker/certs
openssl genrsa -out ca-key.pem 4096
openssl req -new -x509 -days 365 -key ca-key.pem -sha256 -out ca.pem
openssl genrsa -out server-key.pem 4096
openssl req -subj "/CN=YOUR_IP" -sha256 -new -key server-key.pem -out server.csr
openssl x509 -req -days 365 -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out server-cert.pem

after that restart Docker

sudo systemctl restart docker

2. Install Docker Desktop and Configure for Remote Connection

  • Configure Docker Desktop: Open Docker Desktop on Windows.
  • Settings > General: Enable Expose daemon on tcp://localhost:2375 without TLS.
  • Settings > Resources > WSL Integration: Make sure Docker is integrated with your WSL 2 distributions.

3. Configure VSCode for Remote Docker Development

  • Install the Remote - Containers and Docker extensions in VSCode.
  • Open the Command Palette (Ctrl+Shift+P), then select Remote-Containers: Attach to Running Container.

4. Connect to Docker Desktop from VSCode

Now, in VSCode, open the Docker extension and select Connect to Host using the IP of your droplet with port 2376. With Docker Desktop configured for remote development, you can seamlessly work with containers on your DigitalOcean server while managing from your local machine.

Let me know if you’d like help with further configurations or any troubleshooting tips!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more