Featured image of post Hosting Docker in Cloud (Azure)

Hosting Docker in Cloud (Azure)

Setting up docker inside an instance in Azure Cloud

 

Azure part of story

  • First create one Azure account, I am using a student account
  • Create a basic instance (Ubuntu image works for most cases) with 1 vCPU and 1 GiB RAM, or according to your needs
  • Download the private key and SSH into the instance
  • Update the packages
  • Install docker (following this guide)

Let’s move on to the local machine setup

 

Local machine setup

SSH Keys Setup

  • We need to install docker here as well
  • Add ssh key (downloaded from Azure portal) to OpenSSH Auth agent
eval 'ssh-agent'
ssh-add <path-to-pem-file>/<file-name>.pem
  • (or) Add AddKeysToAgent yes to ~/.ssh/config file to automatically do that for you
echo "AddKeysToAgent yes" >> ~/.ssh/config

 

Docker Context Setup

  • Create a new docker context to talk to the docker in Azure instance with command
docker context create azure-box --docker "host=ssh://azureuser@<public-ip-of-instance>"
  • See all available contexts using docker context ls
  • Switching to Azure docker is done using command docker context use azure-box and back to the local docker using docker context use default
  • Now when we issue commands to docker as usual docker ps, it is directly communicating to the docker running in the Azure instance

Note: ‘azure-box’ is just a name, can be replaced with anything of your choice

🎉 Now you have docker running in the cloud, accessible from the terminal

Finally just for testing, we can spin up a Ubuntu container and bash into it:

comments powered by Disqus