Running web application in Docker
Now let's start creating our first image using the Dockerfiles approach:
- Create a folder under C:\ on Windows Server Containers host machine for storing our image artifacts; let's call it learningwsc-chapter2.
- Create another folder within learning-chapter2/hellodocker, which will hold the artifacts for our first image.
- 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" ]
- Save this file as Dockerfile under learningwsc-chapter2/hellodocker.
- 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".
- Open notepad again and copy the following contents:
<h1> Hello from Docker !! </h1>
- 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.
- 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.
- Right-click Windows PowerShell and Run as Administrator.
- Navigate to the folder that contains our artifacts, which is in learningwsc-chapter2/hellodocker:
Cd\
Cd learningwsc-chapter2\hellodocker
- 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!
- The output should look as follows:
- 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.
- You should now be able to see your hellodocker image in the Docker image list: