LET’S TALK DOCKER (PART–2): Dock on Windows

June 27, 2016
admin

Contributor: Sharif Abdullah, Nascenia

This article is a continuation of Let’s Talk Docker (Part-1)

Install Docker Tool Box:

Requirements:
1. Windows 7 or higher
2. Make sure your CPU supports “virtualization technology” and virtualization support is enabled in BIOS and recognized by Windows.

Virtualization support for Windows 8, 8.1 or 10
Choose Start > Task Manager.
Navigate to Performance tab. Under CPU you should see the following:

doc 1

If virtualization is not enabled on your system, follow the manufacturer’s instructions for enabling it.

Virtualization support for Windows 7

Run the Microsoft® Hardware-Assisted Virtualization Detection Tool and follow the on-screen instructions.

Installation

If you have VirtualBox running, you must shut it down before running the installer.

  1. Go to the Docker Toolbox page.
  2. Click the installer link to download.
  3. Install Docker Toolbox by double-clicking the installer. The installer launches the “Setup – Docker Toolbox” dialog.
  4. Press “Next” to install the toolbox.

The installer presents you with options to customize the standard installation. By default, the standard Docker Toolbox installation:

  • installs executables for the Docker tools in C:\Program Files\Docker Toolbox
  • install VirtualBox; or updates any existing installation
  • adds a Docker Inc. folder to your program shortcuts
  • updates your PATH environment variable
  • adds desktop icons for the Docker Quick start Terminal and Kitematic

5. Press “Next” until you reach the “Ready to Install” page. The system prompts you for your password.

6. Press “Install” to continue with the installation. When it completes, the installer provides you with some information you can use to complete some common tasks.

7. Press “Finish” to exit. After Installation you will have these 2 icons in your desktop. One is Docker terminal and another is virtual box UI.

Walk through: Create an Asp.Net app and deploy it into Docker container

Here we’ll go through a quick demo of setting up an empty ASP.NET 5 web application and get it running inside a Docker container on Windows. We’ll go through all the steps necessary to link our project source code into the Docker container and have it run our website. In the end we’ll be able to fire up a view the website running in Docker.

1. Create a new project
Nothing fancy here, let’s create an ASP.NET 5 preview template Web application.
– Select ASP.NET Web Application.

doc 2
– Choose Web Application from the ASP.NET 5 Preview Templates section.

doc 3
– Now you should have an empty web application.

– Now if I try to browse localhost:5000 I will see this:

doc 4
2. Deploy in Docker
Inside the src/DockerDemo folder there should have Docker file. We will need to build docker image.

doc 5

Inside the docker file the following commands should be present:

FROM microsoft/aspnet:1.0.0-rc1-final-coreclr

COPY . /app
WORKDIR /app
RUN [“dnu”, “restore”]

EXPOSE 5000
ENTRYPOINT [“dnx”, “-p”, “project.json”,”web”]

We need to change in the project.json file for setting the port. Change the commands property like this:

“commands”: {
“web”: “Microsoft.AspNet.Server.Kestrel –server.urls http://0.0.0.0:5000”,
“ef”: “EntityFramework.Commands”
}

3. Now start the “Docker Quickstart Terminal”:

It take few minutes to start, if terminal starts successfully you will see this in the terminal:

doc 6

Now we will build  docker image by using that docker file. For that we need to go the folder where the project is located. For my case it is in
“C:\Users\shari_000\projects\DockerDemo\src\DockerDemo”  directory
You can see the all folders and files by ‘dir’ command. Then go project directory:

doc 7

Then run the docker build command,

doc 8

This command will create an image named dockerdemo, you can give any name after that ‘-t’ . The build command will take few minutes to download the dependencies and install them.After the command finished successfully then if you run ‘docker images’  you can see you image listed there.

Now it is time to run a docker container. Docker run commands are like following:

$ docker run -d -p port_number: port_number my_image

So lets run the docker command:

$ docker run -d -p 5000: 5000 dockerdemo

Now we have some few works to do. We need to do port forwarding to virtual box. Open Virtual box and open the settings by right clicking the default running machine.

Docker Installation Process on Windows | Nascenia

Then click on Network->Port Forwarding. You will have a pop up opend. Then click on ‘+’ sign to add new port forwarding rules. Give it a name give the ip adress as the Host Pc local address and make that port 5000:

Docker Installation Process on Windows | Nascenia

Now if you go to browser and browse to http://localhost:5000/, you can see the Asp.Net Home page of the app.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.