Docker noob here...
How does one properly run the docker image of your Asp.Net CORE app which is produced by Visual Studio 2017 at the command line?
docker run -it -d -p 80:32769 myappimage
does not appear to work properly (image runs, but I cannot browse to my app)
Note: I've simply created a sample ASP.Net Core Web App within Studio using the default template, and added Docker support (by clicking the "Add Docker support" checkbox.). Studio adds a dockerfile and some docker-compose files when you do this.
When Visual Studio "runs" the image (by pressing F5) - I can successfully browse to my application ( via "http://localhost:32789" or similar host port. App inside container is on port 80 ). But I cannot figure out the command to run it myself at the command line.
The standard Dockerfile that Studio adds to your project is...
FROM microsoft/aspnetcore:1.1
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "WebApplication2.dll"]
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.
Yes, it is possible. Rebuild your solution in the Release configuration and try to run the
docker-compose
project withF5
to ensure the image is updated and your app is working fine. Then executedocker images
console command. You'll see something like: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 atDockerfile
). For example: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