Skip to content

Latest commit

 

History

History
104 lines (91 loc) · 4.68 KB

challenges.1.md

File metadata and controls

104 lines (91 loc) · 4.68 KB

Single Container Loop Challenge

Why

Containers can make certain aspects of a developer's or admin's life very easy by hiding complexity and by providing reliability. In this chapter you will get a basic experience in working with containers. For this chapter we concentrate on single container applications running locally first and in Azure Container Instances in the second step.

Here's what you'll learn:

  • Container basics
    • Get a feeling for work with containers and understand their purpose
    • Understand what a Dockerfile is
    • How to create a container image
    • How to run a container image locally
    • Get a sense for container networking and ports
    • How to create new versions of images
    • Learn about tagging
    • How to use azure devops automation to set up an automated workflow
  • Deployment
    • How to provide a container image in a registry
    • How to set up a container registry
    • How to run a container in the cloud

1. Containerize your app

This is about putting your apps inside a container

A. Create a container remotely (without docker engine)

https://docs.microsoft.com/en-gb/azure/container-registry/container-registry-tutorial-quick-task

git clone https://github.com/denniszielke/phoenix
  • Go the the aci-hello world app folder
cd phoenix/apps/aci-helloworld/
  • Trigger your azure container registry to build your container remotely
ACR_NAME=
az acr build --registry $ACR_NAME --image helloacrtasks:v1 .
  • Verify the results in your container registry.

B. Create a container locally

  • Create a container image locally (you need docker running on your machine). Don't forget the trailing "." in the following line!
    docker build -t helloworld .
  • Check if the image has been built.
    docker images
  • Run the image in a container locally on your machine. Remember to open up the correct port in your command (-p).
    docker run -d -p 8080:80 helloworld
  • Open the browser and navigate to the application you just started with your browser (http://localhost:8080). If you're running on a Linux VM in Azure, just run this command to avoid working with a graphical browser:
    wget http://localhost:8080
    Then check the content with:
    cat index.html
  • Check the running processes
docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
bc4b6b155c2c        helloworld          "/bin/sh -c 'node /u…"   12 seconds ago      Up 9 seconds        0.0.0.0:8080->8080/tcp   peaceful_mccarthy
  • Kill the process to clean up
docker kill bc4b6b155c2c
  • Push your image to your registry

2. Start your container in azure container instances

This is about checking that your container actually works outside of your dev environment. Need help? Check hints here 📘!

  • Run your newly created image in Azure Container Instances to see if everything works. You can start it manually in the portal or via command line.

3. Automate the build of your container

This is about automating the build of your container outside of your dev environment. Need help? Check hints here 📘!

  • Import the sample code from to your azure devops project. You can do this via UI.
  • Use azure devops to create a build definition which triggers on code changes. The build definition should
    • create a new container image
    • use the build number as tag to identify your image. The buildId can be found in variable $(Build.BuildId) (The screenshots may show Buildnumber - make sure to use the BuildId)
    • push the new image to your private Azure Container Registry (if you don't have an ACR, create one first)

Bonus Challenge 1 - Automate your build using ACR tasks based on Github commits

Need help? Check hints here 📘!

  • Create an ACR Tasks which triggers whenever you update your Github repo.

BONUS Challenge 2 - Update images based on base image changes

Need help? Check hints here 📘!

  • Configure your image to use a base image from your registry
  • Configure a base image trigger