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
- Create or log in to existing account on DigitalOcean.
- Click on Create and select Docker under the Marketplace tab.
- Choose a plan suitable for your project. It is possible to start with a cheap droplet and resize later if the need should arise.
- Select a region for the data center.
- Add SSH key(s), or choose a root password.
- Click on create droplet.
- Wait for the droplet to be created.
Creating a non-root user in droplet
- SSH into the new droplet using
ssh root@<ip address>
- Create a new user using
adduser developer
- Enter the prompted information.
- Add required groups to user with
usermod -aG sudo,docker developer
- If you are using SSH key authentication, copy your SSH key to the new user using
rsync --archive --chown=developer:developer ~/.ssh /home/developer
- Switch user the newly created one using
su developer
- Create a directory for your new app using
mkdir /home/developer/app
Connect VS Code to your droplet
- Install the Remote Development extension for VS Code.
- Open the command palette. (cmd/ctrl + shift + P)
- Select Remote-SSH: Add New SSH Host.
- Select Add New Host.
- Enter "ssh developer@<ip address>".
- Select Remote-SSH: Connect Current Window to Host.
- Select <ip address>.
- Select Linux and click on Continue.
- 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.
- 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 . - Add Silverstripe Sail repository by adding the following to your composer.json.
"repositories": [
{
"type": "vcs",
"url": "https://github.com/olivernorden-silverstripe/silverstripe-sail"
}
] - 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 - Add Silverstripe Sail base configuration by running
./vendor/bin/sail install
- More information about developing with Silverstripe Sail can be found on Silverstripe Sail.
Viewing your application
- Start your application by running
./vendor/bin/sail up -d
- Open the command palette. (cmd/ctrl + shift + P)
- Select Forward a Port and enter desired application port.
- 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.
- Open https://app.ondocker.dev in your browser to view your application.