# Using Docker with NubesGen
Docker is the default option with NubesGen, and allows to run any kind of application supporting Docker.
It comes with two options: "Docker with a Dockerfile" and "Docker with Spring Boot".
# Tutorial: running a Docker image with NubesGen
We're going to deploy https://github.com/jdubois/golang-sample-app (opens new window), which is a sample application written in Go. We'll use NubesGen's GitOps support to automatically build and deploy the application.
Prerequisites:
Tip: You can go to https://aka.ms/nubesgen-azure-shell (opens new window) to have those prerequisites installed, and run the script from a Web browser.
- Bash (opens new window), which is installed by default on most Linux distributions and on Mac OS X. If you're using Windows, one solution is to use WSL (opens new window).
- Azure CLI (opens new window). To login, use
az login
. - (optional) GitHub CLI (opens new window). To login, use
gh auth login
.
Steps:
- Fork the project on your GitHub account.
- Clone the fork on your computer. Change
<your-github-account>
by the name of your GitHub account:git clone https://github.com/<your-github-account>/golang-sample-app.git
- In the cloned project (
cd golang-sample-app
), set up GitOps with NubesGen by using the NubesGen CLI (more information here):./nubesgen-cli-linux gitops
- Use the command-line with NubesGen (more information here) to generate a NubesGen configuration:
curl "https://nubesgen.com/demo.tgz?application=app_service.standard&gitops=true" | tar -xzvf -
- Create a new branch called
env-dev
, and push your code:git checkout -b env-dev git add . git commit -m 'Configure GitOps with NubesGen' git push --set-upstream origin env-dev
- Go to your GitHub project, and check that the GitHub Action is running.
- You can go to the Azure Portal (opens new window) to check the created resources.
- The application should be deployed on your App Service instance. Its URL should be in the form
https://app-demo-XXXX-XXXX-XXXX-XXXX-dev-001.azurewebsites.net/
, and you can also find it in the GitHub Action workflow (Job: "display-information", step "Display Azure infrastructure information"), or in the Azure portal. As it is a simple application, it should print by defaultHello, world
. - Once you have finished, you should clean up your resources:
- Delete the resource group that was created by NubesGen to host your resources, which is named
rg-demo-XXXX-XXXX-XXXX-XXXX-001
. - Delete the storage account used to store your Terraform state, in the
rg-terraform-001
resource group.
# Which Azure resources are created
NubesGen will generate:
- An Azure App Service plan (opens new window) to define the type of App Service instance you will use.
- An Azure App Service instance (opens new window), configured to run your Docker image.
- An Azure Container Registry instance (opens new window) to store your Docker images.
# Configuration options
In the generated terraform/modules/app-service/main.tf
file, NubesGen will configure some environment variables
for your application.
# Important options
WEBSITES_PORT
is the port that will be exposed by your Docker image. By default it is set to8080
, but if your Docker image uses port1337
instead, you will need to reconfigure this accordingly.DOCKER_REGISTRY_SERVER_URL
,DOCKER_REGISTRY_SERVER_USERNAME
andDOCKER_REGISTRY_SERVER_PASSWORD
are used to access the Docker container registry. If you want to use another registry, you need to modify those variables accordingly.
# Other options
DATABASE_URL
: the URL to your databaseDATABASE_USERNAME
: the database user nameDATABASE_PASSWORD
: the database passwordREDIS_HOST
: the Redis host nameREDIS_PASSWORD
: the Redis passwordREDIS_PORT
: the Redis port (by default6380
)AZURE_STORAGE_ACCOUNT_NAME
: the storage account nameAZURE_STORAGE_ACCOUNT_KEY
: the storage account keyAZURE_STORAGE_BLOB_ENDPOINT
: the blob storage endpointMONGODB_DATABASE
: the MongoDB database nameMONGODB_URI
: the MongoDB database URL
# Using a Dockerfile vs using Spring Boot
Using a Dockerfile is the default way to use Docker, so this will work in most situations. NubesGen will build your project using the standard docker build
command.
Spring Boot is a Java framework that can use a Dockerfile, but which uses by default a Maven plugin: this is supported by NubesGen if you select that option, in which case the Docker image will be built using the mvn spring-boot:build-image
command.
If you have selected Spring Boot, NubesGen will also configure the same configuration properties as the ones described in Spring Boot with NubesGen. For example, your database should be automatically configured.