OpenStack / Cloud-init - Deploy Docker Ubuntu VM in under 2 minutes

In this guide, I’ll show you how to deploy a fully configured Ubuntu VM with Docker using cloud-init in OpenStack. With this setup, you’ll have Docker up and running in just under two minutes!
Prerequisites
Before we begin, make sure you have the following ready:
- Access to your OpenStack dashboard or CLI.
- A project/tenant where you can create VMs.
- An Ubuntu cloud image (e.g.,
ubuntu-24.04
) available in your OpenStack image catalog. - A flavor that meets your VM requirements.
- A network configuration set up within OpenStack.
Step 1: Prepare the Cloud-Init Script
Cloud-init automates the initial configuration of your instance. For deploying Docker on Ubuntu, I use the following cloud-init script (cloud-init-docker.yaml):
#cloud-config
runcmd:
- curl -fsSL https://get.docker.com -o get-docker.sh; sh get-docker.sh
# create the docker group
groups:
- docker
# Add default auto created user to docker group
system_info:
default_user:
groups: [docker]
This script installs Docker, enables and starts the Docker service on boot, creates the docker group and also adds the local ubuntu user to the docker group.
Step 2: Launch the VM
Using the OpenStack Dashboard (Horizon)
- Log in to the OpenStack dashboard.
- Navigate to Compute > Instances.
- Click on Launch Instance.
- Fill in the required details:
- Instance Name: Choose a name (e.g.,
ubuntu-docker-vm
). - Source: Select the
ubuntu-24.04
image. - Flavor: Choose a suitable flavor (e.g.,
m1.medium
). - Network: Attach the instance to the required network.
- Instance Name: Choose a name (e.g.,
- Under Configuration, paste the cloud-init script into the Custom Script field.
- Click Launch to create the VM.
Using OpenStack CLI
For those who prefer the command line, here’s how I launch the instance:
openstack server create --flavor m1.medium \
--image ubuntu-24.04 \
--network private \
--key-name mykey \
--user-data cloud-init-docker.yaml \
ubuntu-docker-vm
Make sure to replace your-key
with your SSH key and private
with your network name.
Step 3: Assign a Floating IP (FIP)
Once the VM is active, you’ll need to assign a floating IP so you can access it externally.
From the OpenStack Dashboard
- In the dashboard, go to Compute > Instances.
- Find your VM (e.g.,
ubuntu-docker-vm
), click the dropdown arrow next to Actions, and select Associate Floating IP. - If you don’t already have a floating IP, click + to allocate one from the pool.
- Select the desired floating IP and click Associate.
From the CLI
You can also associate a floating IP using the OpenStack CLI:
openstack floating ip create public
This command creates a floating IP from the public network. To associate it with your VM, use:
openstack server add floating ip docker-vm <FLOATING-IP>
Replace <FLOATING-IP>
with the IP address allocated from the previous step.
Step 4: Access Your Docker VM
With the floating IP assigned, SSH into your VM using the following command:
ssh ubuntu@<FLOATING-IP>
Verify Docker is running by checking the version:
docker --version
You should see the Docker version installed, confirming that your instance is ready for container deployment.
Conclusion
In under two minutes, you’ve deployed an Ubuntu VM with Docker pre-installed and assigned a floating IP for external access using cloud-init in OpenStack. Now you're all set to run your containers! Feel free to modify the cloud-init script to meet your specific requirements.