Skip to content

Containers

William Andrus edited this page Jan 23, 2019 · 9 revisions

Contents

Setup
Create Image
Azure

Setup

  1. Install Docker for Windows: https://docs.docker.com/docker-for-windows/install/

    1. Make sure Virtualization is enabled: Open Task Manager > More Details > Performance and look for "Virtualisation: Enabled" Task Manager Virtualization
    2. Make sure Hyper-V is enabled: Go to Windows Features > Turn Windows features on or off > Hyper V and verify the boxes are checked or black square. Enable Hyper V
    3. Allow Docker to turn on Containers. Docker Enable Containers
  2. Share your hard drive with Docker. Right-click on the docker (whale image) in the system tray, go to settings > share drive and click on the hard drive(s) to share Docker Share C Drive If you're not on your company's domain or using Azure Active Directory, then you might have noticed that the shared drive resets back to being unshared. The easy fix is to create a local account.

    1. Open Settings and navigate to Accounts > Other people > Add User to this PC > I don't have this person's sign-in information > Add a user without a Microsoft account > Create an account for this PC and enter the username.
    2. Make the new account be an Administrator of the machine.

Create Image

  1. Create/Update project with new code. Recommend: Visual Studio or Visual Studio Code for a programming IDE.

  2. In powershell run: docker pull microsoft/dotnet to get all available images from Microsoft.

  3. Create a DockerFile.

    • This could be done in Visual Studio by right clicking on the project > Add > Container Orchestrator Support. Then select "Docker Compose" More Info:VS Docker Setup Info

Visual Studio add DockerFile

-or-

  • Manually create, which ends up being less of a headache. Just drop the file in the same level as the .csproj DockerFile Example
  1. Build. Compile the code to produce your dll and then in powershell:
#build using the dockerfile, replace <tag> with something like: dev, prod, v1, etc...
> docker build -t <tag> . 

Results:

Sending build context to Docker daemon 1.97MB
Step 1/5 : FROM microsoft/dotnet:1.1-runtime AS base
---> 04df21c954d0
Step 2/5 : WORKDIR /app
---> Using cache
---> 55f8f932b5f5
Step 3/5 : COPY /bin/Debug/netcoreapp1.1/publish/ .
---> Using cache
---> b70242b0f3db
Step 4/5 : COPY quotes.json .
---> Using cache
---> 9e95037d294c
Step 5/5 : ENTRYPOINT ["dotnet", "dukenukemquotes.dll"]
---> Using cache
---> a0a5ac02681e
Successfully built a0a5ac02681e
Successfully tagged duke:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

Verify the image was created:

#List all images
docker image --all

Results:

REPOSITORY TAG IMAGE ID CREATED SIZE
duke latest a0a5ac02681e 17 hours ago 253MB

Build the container and run it.

#Create container replace <containerName> with something unique, and used newly created image name (e.g. duke)
docker run --name <containerName> <imageName>

To login into the container using an interactive terminal:

docker run -it --name <containerName> <imageName>

Docker Root Login

Azure

If you need to, install Azure CLI or Azure Powershell

#opens a browser window to login
az login

#open a list of subscriptions, if you have more than one
az account list --output table

#set the subscription to use
az account set --subscription "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

#create a resource group to store everything in (replace myDockerResGrp and westus)
az group create --name myDockerResGrp --location westus

#create a Azure Container Repository to store your image in (replace myDockerResGrp and myACR) 
az acr create --resource-group myDockerResGrp --name myACR--sku Basic --admin-enabled true

#login into your ACR
az acr login --name myACR

#query to get loginserver info (results should be like: "myACR.azurecr.io")
az acr show --name myACR--query loginServer

#query for password to login server
az acr credential show --name myACR --query "passwords[0].value"

#tag the docker image you want to push to the repository, which will make a new one
docker tag myAppImage:v1 myACR.azurecr.io/myAppImage:v1

#tell docker to push the image to Azure
docker push myACR.azurecr.io/myAppImage:v1

#verify image was uploaded
az acr repository list --name myACR --output table

#create a container instance and container with the image (replace myContainer, xxx (password for login server), and uniqueDNSName 
az container create --resource-group myDockerResGrp --name myContainer --image myACR.azurecr.io/myAppImage:v1 --cpu 1 --memory 1 --registry-login-server myACR.azurecr.io --registry-username myACR --registry-password xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --dns-name-label
uniqueDNSName --ports 80

#view logging file
az container logs --resource-group myDockerResGrp --name myContainer
Clone this wiki locally