Volumes

The Docker volume command works just like the “-v” command line parameter we saw in Chapter 2, with the left side of the colon (:) representing the Windows/OSX/Linux directory to mount and the right side representing the destination directory inside the Docker container. Your source code from Windows/OSX/Linux is available to the VirtualBox Linux Docker host using the shared folder feature. It is then further shared from the Docker host to the container using the volume command. As shown below, VirtualBox shared folders convert “C:” into /c/ and convert all Windows path backslashes into Linux-compatible forward slashes. For example, here are the before and after directories for our source code in the Docker host:

Windows Path

c:Users<name>DocumentsDockerBookcatalogProductCatalogsrc
ProductCatalog

Linux VirtualBox Path

/c/Users/<name>/Documents/DockerBook/catalog/ProductCatalog/src/
ProductCatalog

Finally, we use the “thedanfernandez/productcatalog” image, which is an image that when started, restores NuGet packages and starts dnx-watch to listen for changes. This image itself inherits from the “microsoft/aspnet” official image but is designed to ensure it works with the latest set of tooling by the time this book is released.

Another option for developers is to start a container interactively (giving you a standard Linux command prompt inside the running container). One key benefit to this, as mentioned in the third bullet above, is it enables you to download any new packages you might not have included in the Docker image by manually running a package restore whenever you need to. In the example below, we add the “–i” flag to start the service interactively, which will start the bash command prompt running in the container because we specified the entrypoint switch as part of the command as shown in Figure 4.5.

docker run –i –t -p 80:80 –e "server.urls=http://*:80" --entrypoint /
bin/bash
–v
/c/Users/danielfe/Documents/DockerBook/catalog/ProductCatalog/src/
ProductCatalog:/app thedanfernandez/productcatalog

Image

FIGURE 4.5: Starting a container interactively

As you can see, once you have a bash prompt inside a container, you can use standard Linux commands like the ls command to list the contents of the directory to ensure the volume mount command worked correctly. You will next need to run the dnu restore command to restore any dependencies in the project.json file into the container. Once that is complete, run the dnx-watch command to start listening for source code changes and to send/receive web requests.


Image ASP.NET Core 1.0 Changes

Although we’ve tried to make every effort possible to keep the book up-to-date with changing technology, the utilities mentioned above, dnu and dnx-watch are being rebranded to dotnet. What this means is that the commands will change, so for instance, dnu restore will become dotnet restore. Whereas the command names might change, the steps won’t, meaning you will still need to restore NuGet packages and start a “watch” utility to watch for source code changes. The examples on GitHub for this book will be updated to work with any ASP.NET Core 1.0 changes.


Once your web browser is up, you can navigate to the Docker Host IP address and the ProductsController route by going to http://ipaddress/api/products. By default, the IP address would be 192.168.99.100, which with the URL below, returns JSON product information as shown in Figure 4.6.

Image

FIGURE 4.6: Calling the Products REST API

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.187.233