Remote Development With Docker


Reduce workload on your local machine by moving your application to a remote VPS and developing remotely using VS Code and Docker with DigitalOcean.

Setting up DigitalOcean droplet


  1. Create or log in to existing account on DigitalOcean.
  2. Click on Create and select Docker under the Marketplace tab.
  3. Choose a plan suitable for your project. It is possible to start with a cheap droplet and resize later if the need should arise.
  4. Select a region for the data center.
  5. Add SSH key(s), or choose a root password.
  6. Click on create droplet.
  7. Wait for the droplet to be created.

Creating a non-root user in droplet


  1. SSH into the new droplet using
    ssh root@<ip address>
  2. Create a new user using
    adduser developer
  3. Enter the prompted information.
  4. Add required groups to user with
    usermod -aG sudo,docker developer
  5. If you are using SSH key authentication, copy your SSH key to the new user using
    rsync --archive --chown=developer:developer ~/.ssh /home/developer
  6. Switch user the newly created one using
    su developer
  7. Create a directory for your new app using
    mkdir /home/developer/app

Connect VS Code to your droplet


  1. Install the Remote Development extension for VS Code.
  2. Open the command palette. (cmd/ctrl + shift + P)
  3. Select Remote-SSH: Add New SSH Host.
  4. Select Add New Host.
  5. Enter "ssh developer@<ip address>".
  6. Select Remote-SSH: Connect Current Window to Host.
  7. Select <ip address>.
  8. Select Linux and click on Continue.
  9. Click on Open Folder and select app.

Creating your application


For this demo, Silverstripe sail will be used to create a Docker powered development environment for Silverstripe CMS. Any similar Docker set up can be used for remote development with VS Code and DigitalOcean.

  1. Create new Silverstripe CMS application by running the following in a new terminal in VS Code.
    docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v $(pwd):/opt \
    -w /opt \
    nordenoliver/silverstripe-phpcomposer:php73-composer2 \
    composer create-project silverstripe/installer .
  2. Add Silverstripe Sail repository by adding the following to your composer.json.
    "repositories": [
    {
    "type": "vcs",
    "url": "https://github.com/olivernorden-silverstripe/silverstripe-sail"
    }
    ]
  3. Install Silverstripe Sail dependency by running
    docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v $(pwd):/opt \
    -w /opt \
    nordenoliver/silverstripe-phpcomposer:php73-composer2 \
    composer require olivernorden/silverstripe-sail
  4. Add Silverstripe Sail base configuration by running
    ./vendor/bin/sail install
  5. More information about developing with Silverstripe Sail can be found on Silverstripe Sail.

Viewing your application


  1. Start your application by running
    ./vendor/bin/sail up -d
  2. Open the command palette. (cmd/ctrl + shift + P)
  3. Select Forward a Port and enter desired application port.
  4. Repeat for all application ports that need to be accessed externally. For Silverstripe Sail, port 80, 443 (HTTP and HTTPS) and 3306 (Database) should be forwarded.
  5. Open https://app.ondocker.dev in your browser to view your application.