Skip to content

Instantly share code, notes, and snippets.

@joerivanarkel
Last active April 25, 2022 13:00
Show Gist options
  • Save joerivanarkel/31d03a9f1052b30762ff5cb2f4b01519 to your computer and use it in GitHub Desktop.
Save joerivanarkel/31d03a9f1052b30762ff5cb2f4b01519 to your computer and use it in GitHub Desktop.
Docker and Azure Containers

Azure Container

Creating a container instance in Azure follows the basic steps of building an image, creating a container and pushing to registry from Docker Container. The easier way is to push a container directly from VSCode to an Azure Container Registry. Otherwise you can create a Container Instance from a Azure Container Registry container in the Azure Portal, but make sure the right port is opened. Underneath is a GitHub workflow which can automatically create, build and push an image to a container registry on commit.

name: Docker Image
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
USERNAME: huahuahua
PASSWORD: ${{ secrets.REGISTRYPASSWORD }}
LOGINSERVER: huahuahua.azurecr.io
TAG: ${{github.run_number}}
NAME: azurecontainerapi
jobs:
build:
name: Build the Project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
build-container:
name: Build Docker Container and Push to Registry
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: |
docker login huahuahua.azurecr.io -u $USERNAME -p $PASSWORD
docker build . --file Dockerfile --tag $LOGINSERVER/$NAME:$TAG
docker push $LOGINSERVER/azurecontainerapi:$TAG

Docker

When you've created a project you wish to to run as a container, you can dot his in a few simple steps. Firstly you must create a dockerfile, to let docker know what it must do with you project. Most IDE's have this function built in. Secondly you run this command:

docker build -t {LOGINSERVER}/{PROJECTNAME}:TAG .

This creates a image for your container. From here there are many option to create a container and push it to the right location. In VSCode you're able to use the Docker extension, but alternatively you're able to manually push with this command:

docker push {LOGINSERVER}/{PROJECTNAME}:TAG

If you've done all of this successfully your container is now at the right location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment