Learning Windows Server Containers
上QQ阅读APP看书,第一时间看更新

Running web application in Docker

Now let's start creating our first image using the Dockerfiles approach:

  1. Create a folder under C:\ on Windows Server Containers host machine for storing our image artifacts; let's call it learningwsc-chapter2.
  2. Create another folder within learning-chapter2/hellodocker, which will hold the artifacts for our first image.
  3. Open a text editor such as notepad and copy the following contents into the file:
       FROM microsoft/windowsservercore
MAINTAINER srikanth@live.com
LABEL Description="IIS" Vendor=Microsoft" Version="10?
RUN powershell -Command Add-WindowsFeature Web-Server
COPY index.htm /inetpub/wwwroot/
EXPOSE 80
CMD [ "ping localhost -t" ]
  1. Save this file as Dockerfile under learningwsc-chapter2/hellodocker.
  2. Make sure the file is saved without any extension.

To save a file without any extensions under Windows, just surround the filename with "". In this example, save the file as "Dockerfile".

  1. Open notepad again and copy the following contents:
       <h1> Hello from Docker !! </h1>
  1. Save the file as index.htm under learningwsc-chapter2/hellodocker. This serves as our simple HTML application.

Since this book is all about working with Windows Server Containers, the sample applications used to package as containers will be made as simple as possible. However, the same methodologies can be applied for any complex applications. The packaging process is completely decoupled from the application development.

  1. Now that we have all the artifacts ready we can build our first Docker image. Press the Windows key on your keyboard and type PowerShell.
  2. Right-click Windows PowerShell and Run as Administrator.
  3. Navigate to the folder that contains our artifacts, which is in learningwsc-chapter2/hellodocker:
       Cd\
Cd learningwsc-chapter2\hellodocker
  1. Run the following command to build our first Docker image:
       docker build -t hellodocker .

Downloading the example code
Detailed steps to download the code bundle are mentioned in the Preface of this book. The code bundle for the book is also hosted on GitHub at: https://github.com/PacktPublishing/Learning-Windows-Server-Containers. We also have other code bundles from our rich catalog of books and videos available at: https://github.com/PacktPublishing/. Check them out!

  1. The output should look as follows:
  1. Ensure that the log ends with Successfully built [imageidentifier], as shown previously. The image identifier here is the unique ID provided to our image by Docker Engine.
  2. You should now be able to see your hellodocker image in the Docker image list: