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

Using ASP.NET Core 2 with Docker

Now that we've checked Docker is working and can run .NET Core, it's time for something a bit more complex. We're going to interactively log in to a container and create an ASP.NET Core 2 app inside.

Run the following command:

sudo docker run -it --rm microsoft/aspnetcore-build:2

Once the image is downloaded, you should get a slightly different command prompt. Let's be more ambitious and create a single page app using the React and Redux JavaScript libraries:

dotnet new reactredux -o AspNetCoreTwoDocker

Next we need to restore the JS packages from npm. Note that we haven't installed npm (or .NET Core); it has come included in the container image:

cd AspNetCoreTwoDocker

npm install

Let's run the app in the background again and download the home page. Note that the Kestrel web server is now running on the default HTTP port of 80, so we don't need to specify an alternative non-standard port number:

dotnet run &

wget localhost

This is shown in the following screenshot:

The Docker image doesn't contain a text editor, but we can still view the contents of the file with the cat command. We won't get any syntax highlighting, but we can clearly see that this is a React app, as our server rendered the initial state into the page (as div with id of react-app):

cat index.html

The React app HTML page source, displayed in the terminal using cat, is shown in the following screenshot:

You can again tidy up the dotnet process with kill and leave the Docker container to return to your host VM with the exit command.

主站蜘蛛池模板: 社旗县| 平邑县| 犍为县| 隆回县| 若羌县| 上高县| 太白县| 新建县| 黔西县| 惠安县| 上犹县| 海盐县| 利津县| 扎赉特旗| 合水县| 仁化县| 庆阳市| 资兴市| 绵阳市| 淮滨县| 长乐市| 阿克陶县| 漳平市| 永济市| 嵊泗县| 黑河市| 会理县| 独山县| 尉犁县| 富源县| 基隆市| 定西市| 镇江市| 西藏| 白水县| 哈巴河县| 报价| 桂阳县| 温泉县| 余干县| 永年县|