How to run docker image produced by VS 2017 How to run docker image produced by VS 2017 docker docker

How to run docker image produced by VS 2017


Yes, it is possible. Rebuild your solution in the Release configuration and try to run the docker-compose project with F5 to ensure the image is updated and your app is working fine. Then execute docker images console command. You'll see something like:

REPOSITORY   TAG      IMAGE ID       CREATED              SIZEYour.App     latest   673b79a6bb3d   About a minute ago   294 MB

All you need is to run a new container from that image and map its exposed port to a localhost port. By default, the exposed port is 80 (look at Dockerfile). For example:

docker run -d -p 1234:80 --name some_name Your.App:latest

Then your app should become accessible at http://127.0.0.1:1234/.

Explanation:

If the Debug configuration is set, then empty non-workable images are created by Visual Studio. It manually maps the empty container to the filesystem to make possible debugging, "Edit and Continue" features and so on. This is why dev image is useless without Visual Studio. Build the image in the Release configuration to make it usable.

The full publishing process is described in the documentation: Visual Studio Tools for Docker

Publishing Docker images

Once you have completed the develop and debug cycle of your application, the Visual Studio Tools for Docker will help you create the production image of your application. Change the debug dropdown to Release and build the application. The tooling will produce the image with the :latest tag which you can push to your private registry or Docker Hub.


You are confusing here something. When you run your project with F5 in Visual Studio 2017, you run it with IISExpress on a randomly configured port.

In Docker you don't have IISExpress, there your app is only hosted by Kestrel (Kestrel is always used even behind IIS/IISExpress, but they act as reverse proxy).

The default port for Kestrel is 5000, but you can also configure it. See my post here for more detail on which methods you have to configure the listening ip/port.