官术网_书友最值得收藏!

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:
主站蜘蛛池模板: 桂阳县| 枝江市| 玉田县| 揭西县| 太湖县| 从江县| 桂阳县| 隆回县| 柘荣县| 来安县| 嵊州市| 九龙城区| 咸丰县| 旺苍县| 高淳县| 桑日县| 牡丹江市| 通州区| 嘉黎县| 永修县| 高清| 麦盖提县| 依兰县| 沙田区| 蓝山县| 从江县| 萨嘎县| 永年县| 南康市| 齐河县| 中山市| 耿马| 玉山县| 乐至县| 普兰店市| 乐陵市| 乌兰浩特市| 平阴县| 广饶县| 克什克腾旗| 绥芬河市|