Docker Droplet on Digital Ocean

Need a fast, no-fuss way to run Docker in the cloud? DigitalOcean Droplets make it easy. In this guide, you’ll set up a secure, lightweight Docker host in minutes, ideal for quick deployments, side projects, or testing containers without the overhead.

Create Docker Droplet

Install the doctl command-line tool and make sure you have run doctl auth init

Upload your public ssh key. You'll need the key id for the next step.

doctl compute ssh-key list

Now, let's create a droplet. First we need to pick one that suits our needs. We can get a full list of available droplets

doctl compute size list

Let's pick the s-2vcpu-4gb which will cost us $24 per month.

s-2vcpu-4gb                 Basic                                     4096       2        80      24.00            0.035710

We'll use the docker image so that docker is set up and available for us.

doctl compute droplet create digitalocean-docker-example \
--size s-2vcpu-4gb --image docker-20-04 --region nyc1 \
--ssh-keys xxxxxxx

When this is done, you can list them. You'll be able to connect to it once it has a status of active.

doctl compute droplet list

Create a Firewall

Create a firewall to only allow ssh

doctl compute firewall create \
  --name "digitalocean-docker-example-firewall" \
  --inbound-rules "protocol:tcp,ports:22,address:0.0.0.0/0,address:::/0" \
  --outbound-rules "protocol:icmp,address:0.0.0.0/0,address:::/0 protocol:tcp,ports:all,address:0.0.0.0/0,address:::/0 protocol:udp,ports:all,address:0.0.0.0/0,address:::/0" \
 --droplet-ids "YOUR_DROPLET_ID"

Note: you can future secure this by replacing the 0.0.0.0 with your IP address, which you can get with curl ipinfo.io/ip

Connect to it using the IP address and the root user.

ssh root@xxx.xxx.xxx.xxx

Create your own user using Ansible

Ansible is a great way to make sure that your servers are setup the way you want them.

Make sure you have ansible available

brew install ansible

Download the create_my_user ansible playbook from github

ansible-galaxy install git+https://github.com/markcallen/create_my_user.git

Create a user_playbook.yml

- name: Provision user
  hosts: all
  become: yes
  vars:
    user_name: <username>
    ssh_key_url: "https://github.com/<github username>.keys"
  roles:
    - create_my_user

Replace <username> and <github username> with yours

And run on this new host:

ansible-playbook -i "<hostname>," -u root user_playbook.yml 

Watch out the comma in the inventory parameter is important.

Now you can ssh to your host as your username and have access to docker.

ssh <username>@<hostname>

DigitalOcean Droplets offer a quick, simple way to get Docker running in the cloud. With just a few steps, you have a flexible environment ready for containers. Perfect for development, testing, or lightweight production workloads.