SlideShare a Scribd company logo
Azure From Scratch 5
Intro & Setting up cloud
mind-Set
girishkrao.portfoliobox.net
theazureguys.wordpress.com
twitter.com/TheAzureGuy007
facebook.com/TheAzureGuy007
https://github.com/TheAzureGuy007
https://www.linkedin.com/in/girish-kalamati-357a6398/
https://www.youtube.com/channel/UCd9z6-2mZdqjRnAHh3W_9Uw
Docker’s & Container’s
VMWare  Hypervisor  Container’s/Docker’s
Docker’s & Container’s
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Docker Community Edition for Windows 10+
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Running Docker Machine/Client Commands in
MAC OSX
bash --login '/Applications/Docker/Docker Quickstart
Terminal.app/Contents/Resources/Scripts/start.sh'
Last login: Fri Sep 29 22:12:55 on ttys000
Girishs-Mac:~ girishkalamati$ bash --login
'/Applications/Docker/Docker Quickstart
Terminal.app/Contents/Resources/Scripts/start.sh'
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
______ o __/
  __/
___________/
docker is configured to use the default machine with IP
192.168.99.100
For help getting started, check out the docs at
https://docs.docker.com
Running Docker Machine Commands in QuickStart Terminal
Girishs-Mac:~ girishkalamati$ docker-machine ls
NAME ACTIVE DRIVER STATE URL
SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:
2376 v17.09.0-ce
Girishs-Mac:~ girishkalamati$ docker-machine ip
192.168.99.100
Girishs-Mac:~ girishkalamati$ docker-machine state
docker-machine: 'state' is not a docker-machine
command. See 'docker-machine --help'.
Girishs-Mac:~ girishkalamati$ docker-machine status
default
Running
Girishs-Mac:~ girishkalamati$ docker-machine stop
default
Stopping "default"...
Machine "default" was stopped.
Girishs-Mac:~ girishkalamati$ docker-machine start
default
Starting "default"...
(default) Check network to re-create if needed...
(default) Waiting for an IP...
Running Docker Machine Commands in QuickStart Terminal
Started machines may have new IP addresses. You may
need to re-run the `docker-machine env` command.
Girishs-Mac:~ girishkalamati$ docker-machine
Usage: docker-machine [OPTIONS] COMMAND [arg...]
Create and manage machines running Docker.
Version: 0.12.2, build 9371605
Author:
Docker Machine Contributors -
<https://github.com/docker/machine>
Options:
--debug, -D Enable debug mode
--storage-path, -s
"/Users/girishkalamati/.docker/machine" …..
Run 'docker-machine COMMAND --help' for more
information on a command.
Running Docker Machine Commands in QuickStart Terminal
Girishs-Mac:~ girishkalamati$ docker ps
Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon
running?
Girishs-Mac:~ girishkalamati$ docker-machine env
default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export
DOCKER_CERT_PATH="/Users/girishkalamati/.docker/m
achine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)
Girishs-Mac:~ girishkalamati$ eval $(docker-machine
env default)
Girishs-Mac:~ girishkalamati$ docker ps
CONTAINER
ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
Running Docker Machine Commands in Normal Bash
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Girishs-Mac:~ girishkalamati$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
Digest:
sha256:b2ba691d8aac9e5ac3644c0788e3d3823f9e97f75
7f01d2ddc6eb5458df9d801
Status: Image is up to date for hello-world:latest
Girishs-Mac:~ girishkalamati$ docker images
REPOSITORY TAG IMAGE
ID CREATED SIZE
hello-world latest 05a3bd381fc2 2 weeks
ago 1.84kB
Girishs-Mac:~ girishkalamati$ docker run hello-world
Hello from Docker!
This message shows that your installation appears to be
working correctly.
Running Docker Client Commands
To generate this message, Docker took the following
steps:
......
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
Girishs-Mac:~ girishkalamati$ docker ps
CONTAINER
ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
Girishs-Mac:~ girishkalamati$ docker ps -a
CONTAINER
ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
0a42ce8b7770 hello-world "/hello" 4
minutes ago Exited (0) 4 minutes
ago eloquent_jennings
Girishs-Mac:~ girishkalamati$ docker rm 0a42
0a42
Girishs-Mac:~ girishkalamati$ docker ps -a
CONTAINER
Running Docker Client Commands
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
docker is configured to use the default machine with IP
192.168.99.100
For help getting started, check out the docs at
https://docs.docker.com
Girishs-Mac:~ girishkalamati$ docker ps -a
CONTAINER
ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
Girishs-Mac:~ girishkalamati$ docker images
REPOSITORY TAG IMAGE
ID CREATED SIZE
hello-world latest 05a3bd381fc2 2 weeks
ago 1.84kB
Girishs-Mac:~ girishkalamati$ docker rmi 05a3
Untagged: hello-world:latest
Untagged: hello-
world@sha256:b2ba691d8aac9e5ac3644c0788e3d3823f
9e97f757f01d2ddc6eb5458df9d801
Deleted:
sha256:05a3bd381fc2470695a35f230afefd7bf978b56625
3199c4ae5cc96fafa29b37
Deleted:
sha256:3a36971a9f14df69f90891bf24dc2b9ed9c2d20959
b624eab41bbf126272a023
Girishs-Mac:~ girishkalamati$ docker pull
kitematic/hello-world-nginx
Using default tag: latest
latest: Pulling from kitematic/hello-world-nginx
…nginx:latest
Girishs-Mac:~ girishkalamati$ docker images
REPOSITORY TAG IMAGE
ID CREATED SIZE
hello-
world latest 05a3bd381fc2 2
weeks ago 1.84kB
kitematic/hello-world-
nginx latest 03b4557ad7b9 2 years
ago 7.91MB
Girishs-Mac:~ girishkalamati$
Girishs-Mac:~ girishkalamati$ docker run -p 80:80
kitematic/hello-world-nginx
/website_files/index.html not found.
Copying default index.html...
nginx: [alert] could not open error log file: open()
"/var/log/nginx/error.log" failed (2: No such file or
directory)
…..
2017/09/30 07:26:18 [notice] 6#0:
getrlimit(RLIMIT_NOFILE): 1048576:1048576
Azure from scratch part 5 By Girish Kalamati
Girishs-Mac:~ girishkalamati$ docker ps
Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon
running?
Girishs-Mac:~ girishkalamati$ docker-machine env
default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export
DOCKER_CERT_PATH="/Users/girishkalamati/.docker/m
achine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)
Girishs-Mac:~ girishkalamati$ eval $(docker-machine
env default)
Girishs-Mac:~ girishkalamati$ docker ps
CONTAINER
ID IMAGE COMMAND CREAT
ED STATUS PORTS NAMES
0f8a3ec0d161 kitematic/hello-world-nginx "sh
/start.sh" 16 minutes ago Up 16
Running Docker Client Commands
Girishs-Mac:~ girishkalamati$ docker stop of8a
Error response from daemon: No such container: of8a
Girishs-Mac:~ girishkalamati$ docker stop 0f8a3ec0d161
0f8a3ec0d161
Girishs-Mac:~ girishkalamati$ docker ps
CONTAINER
ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
Girishs-Mac:~ girishkalamati$ docker ps -a
CONTAINER
ID IMAGE COMMAND CREAT
ED STATUS PORTS NAM
ES
0f8a3ec0d161 kitematic/hello-world-nginx "sh
/start.sh" 17 minutes ago Exited (137) 21 seconds
ago trusting_swanson
Girishs-Mac:~ girishkalamati$ docker rm 0f8a3ec0d161
0f8a3ec0d161
Girishs-Mac:~ girishkalamati$ docker ps -a
CONTAINER
ID IMAGE COMMAND CREATED
Running Docker Client Commands
Girishs-Mac:~ girishkalamati$ docker images
REPOSITORY TAG IMAGE
ID CREATED SIZE
hello-world latest 05a3bd381fc2 2
weeks ago 1.84kB
kitematic/hello-world-
nginx latest 03b4557ad7b9 2 years
ago 7.91MB
Girishs-Mac:~ girishkalamati$ docker rmi 03b4
Untagged: kitematic/hello-world-nginx:latest
Untagged: kitematic/hello-world-
nginx@sha256:ec0ca6dcb034916784c988b4f2432716e2
e92b9sha256:461f75075df2a334108df11b185363d2afda2
1517fda5ffb10852020e7639b7b
Girishs-Mac:~ girishkalamati$ docker rmi 05a
Untagged: hello-world:latest
Untagged: Deleted:
sha256:3a36971a9f14df69f90891bf24dc2b9ed9c2d20959
b624eab41bbf126272a023
Girishs-Mac:~ girishkalamati$ docker images
REPOSITORY TAG IMAGE
Running Docker Client Commands
• Running a Docker Container
docker run -it <name-of-the-image> <command-to-run>
The -it flag means that we want to start the container in interactive mode, so we can then interact with it on the console. To
run the basic Windows Server Core operating system and starting an interactive command prompt you can use the following
command-line:
docker run -it microsoft/windowsservercore cmd.exe
If you run a Docker container that hosts e.g. a website on the internal port 80, you can
expose that port to the host by specifying the option -p and providing it the source and
destination ports. For example, exposing a website running in a container on port 80, can be
done using the following command-line:
docker run -it -p 80:80 micrsosoft/aspnet
Running Docker CLI
• Looking at running Containers
You can list the running containers by using the command-line
docker ps [-all]
Docker ps -a
this gives a list of all the running containers on your machine or the list of stopped containers when you use the -all option. This
list will look similar to the following:
Running Docker CLI
• Creating an Image
To create an image we can take two approaches.
1. You can commit a container after it has run
2. You can build an image using the Docker build command
• Committing a Container after it has run
let's assume we started a standard Windows Server Core container and in the container we create a folder with the
name c:temp and in the folder we create a file called readme.txt
if we stop the container with the command
docker stop <container-name>
then you will see the container showing up in the list of available containers that you can see with the command
docker ps -all
This means the containers state is still available and we can use that state to create a new layer on top of the existing image.
This is done by using the command
docker commit <name-of-the-stopped-container> <repo:tag>
For example:
docker commit 4e846ab31ff3 myrepo/myapp:v1
docker commit 4e846ab31ff3 theazureguy/mydotnetcoreapp
Running Docker CLI
• Using the Build command
You can also create an image by using a text file called a 'docker file'. A docker file
contains commands that will be executed during a build that will create the required layers.
This includes adding files, adding Windows features or installing your website, copy files and
applications into a container, manipulating registry settings, setting password values and
other general configuration.
A simple Docker file is as follows:
Dockerfile
-------------------------------
FROM microsoft/iis
WORKDIR /inetpub/wwwroot
ADD index.html
In this file we create a new image based on the microsoft/iis image and we add a file to
the c:inetpubwwwroot folder called index.html.
Afterwards, we can run the docker build command with the following command-line:
docker build -t mysampleimage
Dockerfiles always start with the term FROM. This designates the image from which to build the
Running Docker CLI
• Listing Available Images
You can list the available images on your machine by using the command
docker images
This shows all the images that are already locally available and ready for use. If you want to use an image that comes from the
public Docker Hub, you can either just use the run command with the image name you need, or first run the command-line
docker pull <name-of-the-image>
• Removing an container
If you don't want to save the state of a stopped container and just delete it's state, you can use the command-line:
docker rm <name-of-the-stopped-container>
• Removing an image
you can use the command-line:
docker rmi <name/id-of-the-image>
Running Docker CLI
• Docker ps
• Docker ps –a
• Docker search
• Docker pull microsoft/dotnet
• Docker run -d –p 80:80 microsoft/dotnet I.e -d pushing process to background as it’s a large file
• Docker ps –a
• Docker stop <<container id>>
• docker rmi <<IMAGEID>> –f I.e. forcefully removing an image
• docker ps -aq -f status=exited I.e listing out container which r exited
• docker ps -aq --no-trunc | xargs docker rm I.e.Remove stopped containers
• Docker exec -It <<ContainerID>> cmd.exe I.e. opens CMD inside a container and u can explore into IIS files
After entering into the container cmd .. U can run anything on CMD
Dir
CD Inetpub
CD wwwroot
Exit
Docker ps
Docker inspect <<continer id>> I.e. gives info on which IP the docker image/project is hosted
• Docker commit <<continer id>> <<name of the new image>>
Running Docker CLI
• Girish@girishkalamati MINGW64 ~ $ docker commit 222
sha256:368a9137c54fb2742e4678890809f2f11b0620ef2e63df443aebfff0fdb62b6a
• Girish@girishkalamati MINGW64 ~ $ docker images
REPOSITORY TAG IMAGE ID CREATED
SIZE
<none> <none> 368a9137c54f 17 seconds
ago 7.91MB
• docker tag 368a9137c54f mycontainerimage I.e. once u make Image out of another image u can check files u have persisted
earlier.
• docker rm a78 589 I.e. remove Containers with list of containers
Building your own Image
• There are 2 ways of building your own image
1) Building image from running container
Docker ps -a
Docker commit <<container ID>> 'NewImageName'
Docker ps -a
2) Building from any of the images
Files:
Docker File
<Content>
FROM <<DockerImage>>
WORKDIR /inetpub/wwwroot
ADO Index.html Index.Html
<Content>
Commands:
Notepad dockerfile
Docker search microsoft/iis
Docker build -t mycustomiis . I.e. -t is tag , . Is local folder
Docker images
Docker run -d -p 80:80 mycustomiis
Docker exec -it <<continer ID>> CMD I.e exec – Execute
the command
Review-Building your own Image
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Girishs-Mac:~ girishkalamati$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWAR
M DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376
v17.09.0-ce
Girishs-Mac:~ girishkalamati$ dsenableroot
username = girishkalamati
user password:
root password:
verify root password:
dsenableroot:: ***Successfully enabled root user.
Girishs-Mac:~ girishkalamati$ npm install express express-
generator -g
/usr/local/lib
└── express@4.16.1
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm"
"install" "express" "express-generator" "-g"
npm ERR! node v6.11.3
npm ERR! npm v3.10.10
npm ERR! path ../lib/node_modules/express-
generator/bin/express-cli.js
Running Docker Machine/Client Commands in
Windows
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Girishs-Mac:~ girishkalamati$ docker ps
Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon
running?
Girishs-Mac:~ girishkalamati$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export
DOCKER_CERT_PATH="/Users/girishkalamati/.docker/m
achine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)
Girishs-Mac:~ girishkalamati$ eval $(docker-machine env
default)
Girishs-Mac:~ girishkalamati$ docker ps
CONTAINER
ID IMAGE COMMAND CREAT
ED STATUS PORTS NAMES
0f8a3ec0d161 kitematic/hello-world-nginx "sh
/start.sh" 16 minutes ago Up 16
minutes 0.0.0.0:80->80/tcp trusting_swanson
PS C:UsersGirish> docker ps
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.31/containers/json: open
//./pipe/docker_engine: The
system cannot find the file specified. In the default daemon configuration on Windows, the docker
client must be run ele
vated to connect. This error may also indicate that the docker daemon is not running.
PS C:UsersGirish> docker-machine env default
$Env:DOCKER_TLS_VERIFY = "1"
$Env:DOCKER_HOST = "tcp://192.168.99.100:2376"
$Env:DOCKER_CERT_PATH = "C:UsersGirish.dockermachinemachinesdefault"
$Env:DOCKER_MACHINE_NAME = "default"
$Env:COMPOSE_CONVERT_WINDOWS_PATHS = "true"
# Run this command to configure your shell:
# & "C:Program FilesDocker Toolboxdocker-machine.exe" env default | Invoke-Expression
PS C:UsersGirish> & "C:Program FilesDocker Toolboxdocker-machine.exe" env default | Invoke-
Expression
PS C:UsersGirish> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
Running Docker Client Commands
PS C:UsersGirish> docker pull kitematic/hello-world-nginx
Using default tag: latest
latest: Pulling from kitematic/hello-world-nginx
77c6c00e8b61: Pull complete
9b55a9cb10b3: Pull complete
e6cdd97ba74d: Pull complete
7fecf1e9de6b: Pull complete
6b75f22d7bea: Pull complete
e8e00fb8479f: Pull complete
69fad424364c: Pull complete
b3ba6e76b671: Pull complete
a956773dd508: Pull complete
26d2b0603932: Pull complete
3cdbb221209e: Pull complete
a3ed95caeb02: Pull complete
Digest:
sha256:ec0ca6dcb034916784c988b4f2432716e2e92b995ac60
6e080c7a54b52b87066
Status: Downloaded newer image for kitematic/hello-world-
nginx:latest
Importance of Container’s
Old Days when we use to run app’s on Server’s
VMWare Revolution
Even VMWare had loopholes
Azure from scratch part 5 By Girish Kalamati
Docker’s
https://github.com/docker
Docker Hub or Docker Store
https://store.docker.com/
Searching MongoDB Container in Docker Hub or Store
Container Registration
Container Registration
Publishing back the customized container
Publishing back the customized container
Publishing back the customized container
• Logging in to the Docker Registry
Before we can push an image to the registry we need to login. This can be done using the following command-line
docker login -u <username> -p <password>
• All commands that interact with the registry are authenticated. If you are using these commands as part of your build scripts
it is wise to also use the logout command, so the credentials are never left open on the machine.
• Push an Image to default registry
To push an image to the registry you can use the command-line option
docker push <imagename>
• Pull an Image from a default registry
To pull an image from the registry you can first search for an image using the search command. After that you can use
the image name you found to pull it to your machine. You pull an image using the command-line
docker search microsoft
docker pull <imagename>
I.e. docker pull microsoft/dotnet-samples
docker images
docker run 3096 -p: 8080:80
docker-machine ip
docker commit 6f7c mydotnet-samples
docker commit -a GirishKalamati 6f7c theazureguy
Registering Container/ Pushing image to Repository
docker login -u theazureguy -p Girish@#123
docker commit 6f7c mydotnet-samples
docker commit -a GirishKalamati 6f7c theazureguy
docker images
docker tag f1f6c theazureguy/mydotnet-samples
docker push theazureguy/mydotnet-samples
Girishs-Mac:~ girishkalamati$ docker push theazureguy/mydotnet-samples
The push refers to a repository [docker.io/theazureguy/mydotnet-samples]
553c91545c9b: Pushed
d3e0650f9cfc: Mounted from microsoft/dotnet-samples
268629535bef: Mounted from microsoft/dotnet-samples
b7aa89420b4b: Mounted from microsoft/dotnet-samples
0cfdb7afe7d7: Mounted from microsoft/dotnet-samples
7c095a75770b: Mounted from microsoft/dotnet-samples
a75caa09eb1f: Mounted from microsoft/dotnet-samples
latest: digest: sha256:2cef29774c29fd3b7e674b2feea5a3657c3e39505aa1f39592974f6f23f23f73 size: 1783
Registering Container/ Pushing image to Repository
Registering Container into Azure Container Registry
• Choosing another registry
If you want to keep your images private you can run a local registry or when you are using any of the cloud providers, you can
also use their container registries. E.g. Microsoft Azure has a container registry called Azure Container Registry. You can simply
create a registry using either the portal or the Azure Command Line Interface (CLI). With Azure CLI the command is:
az acr create -n <RegistryName> -g <ResourceGroup> -l <region>
Registering Container into Azure Container Registry
• Pushing an image to your own registry
If we now want to push an image to our own private registry we need to first create a tag on our images with our own registry
prefix before pushing it to our registry. This is done with the following command-line:
docker tag <myimage> <registryname>-on.azurecr.io/<image>:<tag>
docker tag f1f6c theazureguyacr.azurecr.io/mydotnet-samples
TheAzureGuyACR
WZ2lce9i*************WIux+fb717
docker login -u <username> -p <password> http://<registryname>.azurecr.io
docker login -u TheAzureGuyACR -p WZ2lce9i*************x+fb717 http://theazureguyacr.azurecr.io
docker tag f1f6c theazureguyacr.azurecr.io/mydotnet-samples
docker push theazureguyacr.azurecr.io/mydotnet-samples
Registering Container into Azure Container Registry
Now we are able to push the image to our own registry. Of course, you need to login to our own registry in the same way we did
before on the Docker Hub.
So for the final push to our private registry the following sequence of command-lines are required:
• Pulling from your own ACR registry
Pulling images from your own registry is as simple as specifying the full image name, including the registry name. So the
following command pulls from our own registry:
docker pull <registryname>-on.azurecr.io/<image>:<tag>
docker pull theazureguyacr.azurecr.io/mydotnet-samples
Registering Container into Azure Container Registry
How Dockers can be useful for us ?
Azure from scratch part 5 By Girish Kalamati
Full CI/CD pipeline to deploy a multi-container
application on Azure Container Service with
Docker Swarm using Visual Studio Team Services
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
In this six-part tutorial, you will:
1.Get set up and oriented, on this page.
2.Build and run your first app
3.Turn your app into a scaling service
4.Span your service across multiple machines
5.Add a visitor counter that persists data
6.Deploy your swarm to production
value of Docker is in how it can build, ship, and run applications; it’s totally agnostic as to
what your application actually does.
Containers vs virtual machines
Virtual Machine diagram Container diagram
$ docker run hello-world
$ docker –version should be higher than 1.13
Containers
Introduction
It’s time to begin building an app the Docker way. We’ll start at the bottom of the hierarchy of such an app, which is
a container
• Stack
• Services
• Container
Let's dockerize an ASP.NET Core application !
Why build ASP.NET Core?
• Open-source
• Develop and run your ASP.NET Core apps cross-platform on Windows, MacOS and Linux
• Great for modern cloud-based apps, such as web apps, IoT apps and mobile backends
• ASP.NET Core apps can run on .NET Core or on the full .NET Framework
• Designed to provide an optimized development framework for apps that are deployed to the cloud or run on-premise
• Modular components with minimal overhead retain flexibility while constructing your solutions
Create a Dockerfile for an ASP.NET Core application
1.Create a Dockerfile in your project folder.
2.Add the text below to your Dockerfile for either Linux or Windows Containers. The tags below are multi-arch
meaning they will pull either Windows or Linux containers depending on what mode is set in Docker for Windows.
Read more on switching containers.
3.The Dockerfile assumes that your application is called aspnetapp. Change the Dockerfile to use the DLL file of
your project.
FROM microsoft/aspnetcore-build:2.0 AS build-env WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./ RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "aspnetapp.dll"]
1.To make your build context as small as possible add a .dockerignore file to your project folder and copy the
following into it.
Bin
obj
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Getting an image from Docker Hub
Docker Hub is the place where open Docker images are stored. When we ran our first image by typing
docker run --rm -p 8080:80 theazureguy/mydotnetcoreapp
the software first checked if this image is available on your computer and since it wasn’t it downloaded the image
from Docker Hub. So getting an image from Docker Hub works sort of automatically.
If you just want to pull the image but not run it, you can also do
docker pull rocker/verse
Getting an image to Docker Hub
Imagine you made your own Docker image and would like to share it with the world you can sign up for an account
on https://hub.docker.com/. After verifying your email you are ready to go and upload your first docker image.
1. Log in on https://hub.docker.com/
2. Click on Create Repository.
3. Choose a name (e.g. theazureguy) and a description for your repository and click Create.
4. Log into the Docker Hub from the command line
docker login --username=theazureguy --email=girish_kalamati@hotmail.com
docker login --username=theazureguy --password=YOURPASSWORD
just with your own user name and email that you used for the account. Enter your password when prompted. If everything
worked you will get a message similar to
WARNING: login credentials saved in /home/username/.docker/config.json
Login Succeeded
Azure from scratch part 5 By Girish Kalamati
Let's Publish image 'mydotnetcoreapp' into docker hub !
Azure from scratch part 5 By Girish Kalamati
Try Dockerize a PHP application !
Define a container with a Dockerfile
Dockerfile will define what goes on in the environment inside your container. Access to resources like
networking interfaces and disk drives is virtualized inside this environment, which is isolated from the rest of your
system, so you have to map ports to the outside world, and be specific about what files you want to “copy in” to
that environment.
However, after doing that, you can expect that the build of your app defined in this Dockerfile will behave exactly
the same wherever it runs.
Dockerfile
Create an empty directory. Change directories (cd) into the new directory, create a file called Dockerfile, copy-
and-paste the following content into that file, and save it. Take note of the comments that explain each statement
in your new Dockerfile.
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati
Azure from scratch part 5 By Girish Kalamati

More Related Content

Azure from scratch part 5 By Girish Kalamati

  • 2. Intro & Setting up cloud mind-Set girishkrao.portfoliobox.net theazureguys.wordpress.com twitter.com/TheAzureGuy007 facebook.com/TheAzureGuy007 https://github.com/TheAzureGuy007 https://www.linkedin.com/in/girish-kalamati-357a6398/ https://www.youtube.com/channel/UCd9z6-2mZdqjRnAHh3W_9Uw
  • 3. Docker’s & Container’s VMWare  Hypervisor  Container’s/Docker’s
  • 26. Docker Community Edition for Windows 10+
  • 31. Running Docker Machine/Client Commands in MAC OSX
  • 32. bash --login '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh' Last login: Fri Sep 29 22:12:55 on ttys000 Girishs-Mac:~ girishkalamati$ bash --login '/Applications/Docker/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh' ## . ## ## ## == ## ## ## ## ## === /"""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~ ______ o __/ __/ ___________/ docker is configured to use the default machine with IP 192.168.99.100 For help getting started, check out the docs at https://docs.docker.com Running Docker Machine Commands in QuickStart Terminal
  • 33. Girishs-Mac:~ girishkalamati$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default * virtualbox Running tcp://192.168.99.100: 2376 v17.09.0-ce Girishs-Mac:~ girishkalamati$ docker-machine ip 192.168.99.100 Girishs-Mac:~ girishkalamati$ docker-machine state docker-machine: 'state' is not a docker-machine command. See 'docker-machine --help'. Girishs-Mac:~ girishkalamati$ docker-machine status default Running Girishs-Mac:~ girishkalamati$ docker-machine stop default Stopping "default"... Machine "default" was stopped. Girishs-Mac:~ girishkalamati$ docker-machine start default Starting "default"... (default) Check network to re-create if needed... (default) Waiting for an IP... Running Docker Machine Commands in QuickStart Terminal
  • 34. Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command. Girishs-Mac:~ girishkalamati$ docker-machine Usage: docker-machine [OPTIONS] COMMAND [arg...] Create and manage machines running Docker. Version: 0.12.2, build 9371605 Author: Docker Machine Contributors - <https://github.com/docker/machine> Options: --debug, -D Enable debug mode --storage-path, -s "/Users/girishkalamati/.docker/machine" ….. Run 'docker-machine COMMAND --help' for more information on a command. Running Docker Machine Commands in QuickStart Terminal
  • 35. Girishs-Mac:~ girishkalamati$ docker ps Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? Girishs-Mac:~ girishkalamati$ docker-machine env default export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/girishkalamati/.docker/m achine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval $(docker-machine env default) Girishs-Mac:~ girishkalamati$ eval $(docker-machine env default) Girishs-Mac:~ girishkalamati$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES Running Docker Machine Commands in Normal Bash
  • 38. Girishs-Mac:~ girishkalamati$ docker pull hello-world Using default tag: latest latest: Pulling from library/hello-world Digest: sha256:b2ba691d8aac9e5ac3644c0788e3d3823f9e97f75 7f01d2ddc6eb5458df9d801 Status: Image is up to date for hello-world:latest Girishs-Mac:~ girishkalamati$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 05a3bd381fc2 2 weeks ago 1.84kB Girishs-Mac:~ girishkalamati$ docker run hello-world Hello from Docker! This message shows that your installation appears to be working correctly. Running Docker Client Commands
  • 39. To generate this message, Docker took the following steps: ...... For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ Girishs-Mac:~ girishkalamati$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES Girishs-Mac:~ girishkalamati$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0a42ce8b7770 hello-world "/hello" 4 minutes ago Exited (0) 4 minutes ago eloquent_jennings Girishs-Mac:~ girishkalamati$ docker rm 0a42 0a42 Girishs-Mac:~ girishkalamati$ docker ps -a CONTAINER Running Docker Client Commands
  • 42. docker is configured to use the default machine with IP 192.168.99.100 For help getting started, check out the docs at https://docs.docker.com Girishs-Mac:~ girishkalamati$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES Girishs-Mac:~ girishkalamati$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 05a3bd381fc2 2 weeks ago 1.84kB Girishs-Mac:~ girishkalamati$ docker rmi 05a3 Untagged: hello-world:latest Untagged: hello- world@sha256:b2ba691d8aac9e5ac3644c0788e3d3823f 9e97f757f01d2ddc6eb5458df9d801 Deleted: sha256:05a3bd381fc2470695a35f230afefd7bf978b56625 3199c4ae5cc96fafa29b37 Deleted: sha256:3a36971a9f14df69f90891bf24dc2b9ed9c2d20959 b624eab41bbf126272a023
  • 43. Girishs-Mac:~ girishkalamati$ docker pull kitematic/hello-world-nginx Using default tag: latest latest: Pulling from kitematic/hello-world-nginx …nginx:latest Girishs-Mac:~ girishkalamati$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello- world latest 05a3bd381fc2 2 weeks ago 1.84kB kitematic/hello-world- nginx latest 03b4557ad7b9 2 years ago 7.91MB Girishs-Mac:~ girishkalamati$ Girishs-Mac:~ girishkalamati$ docker run -p 80:80 kitematic/hello-world-nginx /website_files/index.html not found. Copying default index.html... nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (2: No such file or directory) ….. 2017/09/30 07:26:18 [notice] 6#0: getrlimit(RLIMIT_NOFILE): 1048576:1048576
  • 45. Girishs-Mac:~ girishkalamati$ docker ps Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? Girishs-Mac:~ girishkalamati$ docker-machine env default export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/girishkalamati/.docker/m achine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval $(docker-machine env default) Girishs-Mac:~ girishkalamati$ eval $(docker-machine env default) Girishs-Mac:~ girishkalamati$ docker ps CONTAINER ID IMAGE COMMAND CREAT ED STATUS PORTS NAMES 0f8a3ec0d161 kitematic/hello-world-nginx "sh /start.sh" 16 minutes ago Up 16 Running Docker Client Commands
  • 46. Girishs-Mac:~ girishkalamati$ docker stop of8a Error response from daemon: No such container: of8a Girishs-Mac:~ girishkalamati$ docker stop 0f8a3ec0d161 0f8a3ec0d161 Girishs-Mac:~ girishkalamati$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES Girishs-Mac:~ girishkalamati$ docker ps -a CONTAINER ID IMAGE COMMAND CREAT ED STATUS PORTS NAM ES 0f8a3ec0d161 kitematic/hello-world-nginx "sh /start.sh" 17 minutes ago Exited (137) 21 seconds ago trusting_swanson Girishs-Mac:~ girishkalamati$ docker rm 0f8a3ec0d161 0f8a3ec0d161 Girishs-Mac:~ girishkalamati$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED Running Docker Client Commands
  • 47. Girishs-Mac:~ girishkalamati$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 05a3bd381fc2 2 weeks ago 1.84kB kitematic/hello-world- nginx latest 03b4557ad7b9 2 years ago 7.91MB Girishs-Mac:~ girishkalamati$ docker rmi 03b4 Untagged: kitematic/hello-world-nginx:latest Untagged: kitematic/hello-world- nginx@sha256:ec0ca6dcb034916784c988b4f2432716e2 e92b9sha256:461f75075df2a334108df11b185363d2afda2 1517fda5ffb10852020e7639b7b Girishs-Mac:~ girishkalamati$ docker rmi 05a Untagged: hello-world:latest Untagged: Deleted: sha256:3a36971a9f14df69f90891bf24dc2b9ed9c2d20959 b624eab41bbf126272a023 Girishs-Mac:~ girishkalamati$ docker images REPOSITORY TAG IMAGE Running Docker Client Commands
  • 48. • Running a Docker Container docker run -it <name-of-the-image> <command-to-run> The -it flag means that we want to start the container in interactive mode, so we can then interact with it on the console. To run the basic Windows Server Core operating system and starting an interactive command prompt you can use the following command-line: docker run -it microsoft/windowsservercore cmd.exe If you run a Docker container that hosts e.g. a website on the internal port 80, you can expose that port to the host by specifying the option -p and providing it the source and destination ports. For example, exposing a website running in a container on port 80, can be done using the following command-line: docker run -it -p 80:80 micrsosoft/aspnet Running Docker CLI
  • 49. • Looking at running Containers You can list the running containers by using the command-line docker ps [-all] Docker ps -a this gives a list of all the running containers on your machine or the list of stopped containers when you use the -all option. This list will look similar to the following: Running Docker CLI
  • 50. • Creating an Image To create an image we can take two approaches. 1. You can commit a container after it has run 2. You can build an image using the Docker build command • Committing a Container after it has run let's assume we started a standard Windows Server Core container and in the container we create a folder with the name c:temp and in the folder we create a file called readme.txt if we stop the container with the command docker stop <container-name> then you will see the container showing up in the list of available containers that you can see with the command docker ps -all This means the containers state is still available and we can use that state to create a new layer on top of the existing image. This is done by using the command docker commit <name-of-the-stopped-container> <repo:tag> For example: docker commit 4e846ab31ff3 myrepo/myapp:v1 docker commit 4e846ab31ff3 theazureguy/mydotnetcoreapp Running Docker CLI
  • 51. • Using the Build command You can also create an image by using a text file called a 'docker file'. A docker file contains commands that will be executed during a build that will create the required layers. This includes adding files, adding Windows features or installing your website, copy files and applications into a container, manipulating registry settings, setting password values and other general configuration. A simple Docker file is as follows: Dockerfile ------------------------------- FROM microsoft/iis WORKDIR /inetpub/wwwroot ADD index.html In this file we create a new image based on the microsoft/iis image and we add a file to the c:inetpubwwwroot folder called index.html. Afterwards, we can run the docker build command with the following command-line: docker build -t mysampleimage Dockerfiles always start with the term FROM. This designates the image from which to build the Running Docker CLI
  • 52. • Listing Available Images You can list the available images on your machine by using the command docker images This shows all the images that are already locally available and ready for use. If you want to use an image that comes from the public Docker Hub, you can either just use the run command with the image name you need, or first run the command-line docker pull <name-of-the-image> • Removing an container If you don't want to save the state of a stopped container and just delete it's state, you can use the command-line: docker rm <name-of-the-stopped-container> • Removing an image you can use the command-line: docker rmi <name/id-of-the-image> Running Docker CLI
  • 53. • Docker ps • Docker ps –a • Docker search • Docker pull microsoft/dotnet • Docker run -d –p 80:80 microsoft/dotnet I.e -d pushing process to background as it’s a large file • Docker ps –a • Docker stop <<container id>> • docker rmi <<IMAGEID>> –f I.e. forcefully removing an image • docker ps -aq -f status=exited I.e listing out container which r exited • docker ps -aq --no-trunc | xargs docker rm I.e.Remove stopped containers • Docker exec -It <<ContainerID>> cmd.exe I.e. opens CMD inside a container and u can explore into IIS files After entering into the container cmd .. U can run anything on CMD Dir CD Inetpub CD wwwroot Exit Docker ps Docker inspect <<continer id>> I.e. gives info on which IP the docker image/project is hosted • Docker commit <<continer id>> <<name of the new image>> Running Docker CLI
  • 54. • Girish@girishkalamati MINGW64 ~ $ docker commit 222 sha256:368a9137c54fb2742e4678890809f2f11b0620ef2e63df443aebfff0fdb62b6a • Girish@girishkalamati MINGW64 ~ $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 368a9137c54f 17 seconds ago 7.91MB • docker tag 368a9137c54f mycontainerimage I.e. once u make Image out of another image u can check files u have persisted earlier. • docker rm a78 589 I.e. remove Containers with list of containers Building your own Image
  • 55. • There are 2 ways of building your own image 1) Building image from running container Docker ps -a Docker commit <<container ID>> 'NewImageName' Docker ps -a 2) Building from any of the images Files: Docker File <Content> FROM <<DockerImage>> WORKDIR /inetpub/wwwroot ADO Index.html Index.Html <Content> Commands: Notepad dockerfile Docker search microsoft/iis Docker build -t mycustomiis . I.e. -t is tag , . Is local folder Docker images Docker run -d -p 80:80 mycustomiis Docker exec -it <<continer ID>> CMD I.e exec – Execute the command Review-Building your own Image
  • 71. Girishs-Mac:~ girishkalamati$ docker-machine ls NAME ACTIVE DRIVER STATE URL SWAR M DOCKER ERRORS default * virtualbox Running tcp://192.168.99.100:2376 v17.09.0-ce Girishs-Mac:~ girishkalamati$ dsenableroot username = girishkalamati user password: root password: verify root password: dsenableroot:: ***Successfully enabled root user. Girishs-Mac:~ girishkalamati$ npm install express express- generator -g /usr/local/lib └── express@4.16.1 npm ERR! Darwin 15.6.0 npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "express" "express-generator" "-g" npm ERR! node v6.11.3 npm ERR! npm v3.10.10 npm ERR! path ../lib/node_modules/express- generator/bin/express-cli.js
  • 72. Running Docker Machine/Client Commands in Windows
  • 75. Girishs-Mac:~ girishkalamati$ docker ps Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? Girishs-Mac:~ girishkalamati$ docker-machine env default export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/girishkalamati/.docker/m achine/machines/default" export DOCKER_MACHINE_NAME="default" # Run this command to configure your shell: # eval $(docker-machine env default) Girishs-Mac:~ girishkalamati$ eval $(docker-machine env default) Girishs-Mac:~ girishkalamati$ docker ps CONTAINER ID IMAGE COMMAND CREAT ED STATUS PORTS NAMES 0f8a3ec0d161 kitematic/hello-world-nginx "sh /start.sh" 16 minutes ago Up 16 minutes 0.0.0.0:80->80/tcp trusting_swanson
  • 76. PS C:UsersGirish> docker ps error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.31/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run ele vated to connect. This error may also indicate that the docker daemon is not running. PS C:UsersGirish> docker-machine env default $Env:DOCKER_TLS_VERIFY = "1" $Env:DOCKER_HOST = "tcp://192.168.99.100:2376" $Env:DOCKER_CERT_PATH = "C:UsersGirish.dockermachinemachinesdefault" $Env:DOCKER_MACHINE_NAME = "default" $Env:COMPOSE_CONVERT_WINDOWS_PATHS = "true" # Run this command to configure your shell: # & "C:Program FilesDocker Toolboxdocker-machine.exe" env default | Invoke-Expression PS C:UsersGirish> & "C:Program FilesDocker Toolboxdocker-machine.exe" env default | Invoke- Expression PS C:UsersGirish> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES Running Docker Client Commands
  • 77. PS C:UsersGirish> docker pull kitematic/hello-world-nginx Using default tag: latest latest: Pulling from kitematic/hello-world-nginx 77c6c00e8b61: Pull complete 9b55a9cb10b3: Pull complete e6cdd97ba74d: Pull complete 7fecf1e9de6b: Pull complete 6b75f22d7bea: Pull complete e8e00fb8479f: Pull complete 69fad424364c: Pull complete b3ba6e76b671: Pull complete a956773dd508: Pull complete 26d2b0603932: Pull complete 3cdbb221209e: Pull complete a3ed95caeb02: Pull complete Digest: sha256:ec0ca6dcb034916784c988b4f2432716e2e92b995ac60 6e080c7a54b52b87066 Status: Downloaded newer image for kitematic/hello-world- nginx:latest
  • 79. Old Days when we use to run app’s on Server’s
  • 81. Even VMWare had loopholes
  • 85. Docker Hub or Docker Store https://store.docker.com/
  • 86. Searching MongoDB Container in Docker Hub or Store
  • 89. Publishing back the customized container
  • 90. Publishing back the customized container
  • 91. Publishing back the customized container
  • 92. • Logging in to the Docker Registry Before we can push an image to the registry we need to login. This can be done using the following command-line docker login -u <username> -p <password> • All commands that interact with the registry are authenticated. If you are using these commands as part of your build scripts it is wise to also use the logout command, so the credentials are never left open on the machine. • Push an Image to default registry To push an image to the registry you can use the command-line option docker push <imagename> • Pull an Image from a default registry To pull an image from the registry you can first search for an image using the search command. After that you can use the image name you found to pull it to your machine. You pull an image using the command-line docker search microsoft docker pull <imagename> I.e. docker pull microsoft/dotnet-samples docker images docker run 3096 -p: 8080:80 docker-machine ip docker commit 6f7c mydotnet-samples docker commit -a GirishKalamati 6f7c theazureguy Registering Container/ Pushing image to Repository
  • 93. docker login -u theazureguy -p Girish@#123 docker commit 6f7c mydotnet-samples docker commit -a GirishKalamati 6f7c theazureguy docker images docker tag f1f6c theazureguy/mydotnet-samples docker push theazureguy/mydotnet-samples Girishs-Mac:~ girishkalamati$ docker push theazureguy/mydotnet-samples The push refers to a repository [docker.io/theazureguy/mydotnet-samples] 553c91545c9b: Pushed d3e0650f9cfc: Mounted from microsoft/dotnet-samples 268629535bef: Mounted from microsoft/dotnet-samples b7aa89420b4b: Mounted from microsoft/dotnet-samples 0cfdb7afe7d7: Mounted from microsoft/dotnet-samples 7c095a75770b: Mounted from microsoft/dotnet-samples a75caa09eb1f: Mounted from microsoft/dotnet-samples latest: digest: sha256:2cef29774c29fd3b7e674b2feea5a3657c3e39505aa1f39592974f6f23f23f73 size: 1783 Registering Container/ Pushing image to Repository
  • 94. Registering Container into Azure Container Registry
  • 95. • Choosing another registry If you want to keep your images private you can run a local registry or when you are using any of the cloud providers, you can also use their container registries. E.g. Microsoft Azure has a container registry called Azure Container Registry. You can simply create a registry using either the portal or the Azure Command Line Interface (CLI). With Azure CLI the command is: az acr create -n <RegistryName> -g <ResourceGroup> -l <region> Registering Container into Azure Container Registry
  • 96. • Pushing an image to your own registry If we now want to push an image to our own private registry we need to first create a tag on our images with our own registry prefix before pushing it to our registry. This is done with the following command-line: docker tag <myimage> <registryname>-on.azurecr.io/<image>:<tag> docker tag f1f6c theazureguyacr.azurecr.io/mydotnet-samples TheAzureGuyACR WZ2lce9i*************WIux+fb717 docker login -u <username> -p <password> http://<registryname>.azurecr.io docker login -u TheAzureGuyACR -p WZ2lce9i*************x+fb717 http://theazureguyacr.azurecr.io docker tag f1f6c theazureguyacr.azurecr.io/mydotnet-samples docker push theazureguyacr.azurecr.io/mydotnet-samples Registering Container into Azure Container Registry
  • 97. Now we are able to push the image to our own registry. Of course, you need to login to our own registry in the same way we did before on the Docker Hub. So for the final push to our private registry the following sequence of command-lines are required: • Pulling from your own ACR registry Pulling images from your own registry is as simple as specifying the full image name, including the registry name. So the following command pulls from our own registry: docker pull <registryname>-on.azurecr.io/<image>:<tag> docker pull theazureguyacr.azurecr.io/mydotnet-samples Registering Container into Azure Container Registry
  • 98. How Dockers can be useful for us ?
  • 100. Full CI/CD pipeline to deploy a multi-container application on Azure Container Service with Docker Swarm using Visual Studio Team Services
  • 103. In this six-part tutorial, you will: 1.Get set up and oriented, on this page. 2.Build and run your first app 3.Turn your app into a scaling service 4.Span your service across multiple machines 5.Add a visitor counter that persists data 6.Deploy your swarm to production value of Docker is in how it can build, ship, and run applications; it’s totally agnostic as to what your application actually does.
  • 104. Containers vs virtual machines Virtual Machine diagram Container diagram
  • 105. $ docker run hello-world $ docker –version should be higher than 1.13 Containers Introduction It’s time to begin building an app the Docker way. We’ll start at the bottom of the hierarchy of such an app, which is a container • Stack • Services • Container Let's dockerize an ASP.NET Core application !
  • 106. Why build ASP.NET Core? • Open-source • Develop and run your ASP.NET Core apps cross-platform on Windows, MacOS and Linux • Great for modern cloud-based apps, such as web apps, IoT apps and mobile backends • ASP.NET Core apps can run on .NET Core or on the full .NET Framework • Designed to provide an optimized development framework for apps that are deployed to the cloud or run on-premise • Modular components with minimal overhead retain flexibility while constructing your solutions
  • 107. Create a Dockerfile for an ASP.NET Core application 1.Create a Dockerfile in your project folder. 2.Add the text below to your Dockerfile for either Linux or Windows Containers. The tags below are multi-arch meaning they will pull either Windows or Linux containers depending on what mode is set in Docker for Windows. Read more on switching containers. 3.The Dockerfile assumes that your application is called aspnetapp. Change the Dockerfile to use the DLL file of your project. FROM microsoft/aspnetcore-build:2.0 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore # Copy everything else and build COPY . ./ RUN dotnet publish -c Release -o out # Build runtime image FROM microsoft/aspnetcore:2.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT ["dotnet", "aspnetapp.dll"] 1.To make your build context as small as possible add a .dockerignore file to your project folder and copy the following into it. Bin obj
  • 118. Getting an image from Docker Hub Docker Hub is the place where open Docker images are stored. When we ran our first image by typing docker run --rm -p 8080:80 theazureguy/mydotnetcoreapp the software first checked if this image is available on your computer and since it wasn’t it downloaded the image from Docker Hub. So getting an image from Docker Hub works sort of automatically. If you just want to pull the image but not run it, you can also do docker pull rocker/verse Getting an image to Docker Hub Imagine you made your own Docker image and would like to share it with the world you can sign up for an account on https://hub.docker.com/. After verifying your email you are ready to go and upload your first docker image. 1. Log in on https://hub.docker.com/ 2. Click on Create Repository. 3. Choose a name (e.g. theazureguy) and a description for your repository and click Create. 4. Log into the Docker Hub from the command line docker login --username=theazureguy --email=girish_kalamati@hotmail.com docker login --username=theazureguy --password=YOURPASSWORD just with your own user name and email that you used for the account. Enter your password when prompted. If everything worked you will get a message similar to WARNING: login credentials saved in /home/username/.docker/config.json Login Succeeded
  • 120. Let's Publish image 'mydotnetcoreapp' into docker hub !
  • 122. Try Dockerize a PHP application !
  • 123. Define a container with a Dockerfile Dockerfile will define what goes on in the environment inside your container. Access to resources like networking interfaces and disk drives is virtualized inside this environment, which is isolated from the rest of your system, so you have to map ports to the outside world, and be specific about what files you want to “copy in” to that environment. However, after doing that, you can expect that the build of your app defined in this Dockerfile will behave exactly the same wherever it runs. Dockerfile Create an empty directory. Change directories (cd) into the new directory, create a file called Dockerfile, copy- and-paste the following content into that file, and save it. Take note of the comments that explain each statement in your new Dockerfile. # Use an official Python runtime as a parent image FROM python:2.7-slim # Set the working directory to /app WORKDIR /app # Copy the current directory contents into the container at /app ADD . /app # Install any needed packages specified in requirements.txt RUN pip install -r requirements.txt # Make port 80 available to the world outside this container EXPOSE 80 # Define environment variable ENV NAME World # Run app.py when the container launches CMD ["python", "app.py"]

Editor's Notes

  1. The Case for Containers The concepts behind Docker and other Linux containers are solid: Very small VMs that allow for much higher server density by removing redundant or unnecessary operating system elements from the VMs themselves. Nicely packaged VM stacks, which can easily be transferred, replicated, and controlled, ensuring high levels of portability. VM software stacks that are small, removing the problem and tedium of building a large stack of version-specific operating systems and tools that need lots of care and feeding to replicate and maintain. Extremely fast startup times that can facilitate a more flexible infrastructure, allowing greater latitude to respond to the needs of the moment – literally.
  2. The Case for Containers The concepts behind Docker and other Linux containers are solid: Very small VMs that allow for much higher server density by removing redundant or unnecessary operating system elements from the VMs themselves. Nicely packaged VM stacks, which can easily be transferred, replicated, and controlled, ensuring high levels of portability. VM software stacks that are small, removing the problem and tedium of building a large stack of version-specific operating systems and tools that need lots of care and feeding to replicate and maintain. Extremely fast startup times that can facilitate a more flexible infrastructure, allowing greater latitude to respond to the needs of the moment – literally.
  3. Docker containers are configured to maintain all configurations and dependencies internally. As a result, you can use the same container from development to production making sure there are no discrepancies or manual intervention.
  4. Docker Machine Overview : You can use Docker Machine to: Install and run Docker on Mac or Windows Provision and manage multiple remote Docker hosts Provision Swarm clusters What is Docker Machine? Docker Machine is a tool that lets you install Docker Engine on virtual hosts, and manage the hosts with docker-machine commands. You can use Machine to create Docker hosts on your local Mac or Windows box, on your company network, in your data center, or on cloud providers like Azure, AWS, or Digital Ocean. Using docker-machine commands, you can start, inspect, stop, and restart a managed host, upgrade the Docker client and daemon, and configure a Docker client to talk to your host. Point the Machine CLI at a running, managed host, and you can run docker commands directly on that host. For example, run docker-machine env default to point to a host called default, follow on-screen instructions to complete env setup, and run docker ps, docker run hello-world, and so forth. Machine was the only way to run Docker on Mac or Windows previous to Docker v1.12. Starting with the beta program and Docker v1.12, Docker for Mac and Docker for Windows are available as native apps and the better choice for this use case on newer desktops and laptops. We encourage you to try out these new apps. The installers for Docker for Mac and Docker for Windows include Docker Machine, along with Docker Compose.
  5. Machine was the only way to run Docker on Mac or Windows previous to Docker v1.12. Starting with the beta program and Docker v1.12, Docker for Mac and Docker for Windows are available as native apps and the better choice for this use case on newer desktops and laptops.
  6. Machine was the only way to run Docker on Mac or Windows previous to Docker v1.12. Starting with the beta program and Docker v1.12, Docker for Mac and Docker for Windows are available as native apps and the better choice for this use case on newer desktops and laptops.
  7. Running Docker Codes in QuickStart Terminal
  8. Running Docker Codes in QuickStart Terminal
  9. Running Docker Codes in QuickStart Terminal
  10. Running Docker Codes in Bash Terminal
  11. Running Docker Codes in Bash Terminal
  12. Running Docker Codes in Bash Terminal
  13. Docker-machine ls Docker-machine env ubuntu
  14. Docker run mysampleimage Docker-machine ip Or  Docker-machine inspect "containerID"
  15. Docker run –p 8080:3000 -v /var/www node Docker run –p 8080:3000 -v /var/www mycontainerimage Localhost:8080  Or  IP:8080 Node == image name It will create a container inside host … even it says Container volume 
  16. Docker inspect myconatiner
  17. Custom folder to put source code in HOST
  18. Docker run –p 8080:3000 –v $(pwd):/var/www node Node == image name It will create a container inside host … even it says Container volume 
  19. Docker inspect mycontainer
  20. We also need to assume you are familiar with a few concepts before we continue: IP Addresses and Ports Virtual Machines Editing configuration files Basic familiarity with the ideas of code dependencies and building Machine resource usage terms, like CPU percentages, RAM use in bytes, etc.
  21. A brief explanation of containers An image is a lightweight, stand-alone, executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries, environment variables, and config files. A container is a runtime instance of an image—what the image becomes in memory when actually executed. It runs completely isolated from the host environment by default, only accessing host files and ports if configured to do so. Containers run apps natively on the host machine’s kernel. They have better performance characteristics than virtual machines that only get virtual access to host resources through a hypervisor. Containers can get native access, each one running in a discrete process, taking no more memory than any other executable. Virtual machines run guest operating systems—note the OS layer in each box. This is resource intensive, and the resulting disk image and application state is an entanglement of OS settings, system-installed dependencies, OS security patches, and other easy-to-lose, hard-to-replicate ephemera.
  22. Conclusion The unit of scale being an individual, portable executable has vast implications. It means CI/CD can push updates to any part of a distributed application, system dependencies are not an issue, and resource density is increased. Orchestration of scaling behavior is a matter of spinning up new executables, not new VM hosts.
  23. View the web page running from a container Go to localhost:8080 to access your app in a web browser. If you are using the Nano Windows Container and have not updated to the Windows Creator Update there is a bug affecting how Windows 10 talks to Containers via “NAT”(Network Address Translation). You must hit the IP of the container directly. You can get the IP address of your container with the following steps: Run docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" myapp Copy the container ip address and paste into your browser. (For example, 172.16.240.197)
  24. Are you behind a proxy server? Proxy servers can block connections to your web app once it’s up and running. If you are behind a proxy server, add the following lines to your Dockerfile, using the ENV command to specify the host and port for your proxy servers: # Set proxy server, replace host:/port with values for your servers ENV http_proxy host:/port ENV https_proxy host:/port
  25. Orchestration comes when we create Multi Hosts .. since distributed applications cannot be hosted on a single host because tht would be a single point of failure.
  26. Yellow : Master  Orange : Workers
  27. Container Level Dependencies are defined by Compose.yaml but Application level dependency/Resiliency is developers responsibility Because We have different types of containers I.e. Web Containers and DB Containers can come up at different times. DB containers can take time to come up it would be great if developers writes some code which can ping the DB container asking whether it is up ? And Then Web Container should redirect requests.
  28. Task == Container
  29. -p 8080:8080  1st 8080 is Host Port No 2nd 8080 is Container Port No For this kind of Multiple Hosts we Have Ingress Port at HOST which can be a single value like 8080 here , Since Load Balancers are Host aware not Container aware.  In cases when requests come from LB if some host is having issue, the container can be moved to healthy host and this mapping with 8080 will be there on the new node. The mapping will be updated into IPTable.
  30. In cases when requests come from LB if some host is having issue, the container can be moved to healthy host and this mapping with 8080 will be there on the new node. The mapping will be updated into IPTable. Requests automatically redirected to right Host basing upon IPTable.  IPTable could be managed on single HUB and u can assure that u r requests will land on to only host where container is running :)