I unable to get container IP address to run it from Browser.
Code Snippet
PS H:\DevAreaLocal\COMPANY - RAD PROJECTS\DockerApp\WebDockerCoreApp> docker-compose build
Building webdockercoreapp
Step 1/5 : FROM microsoft/aspnetcore:1.1
---> 4fe9b4d0d093
Step 2/5 : WORKDIR /WebDockerCoreApp
---> Using cache
---> b1536c639a21
Step 3/5 : COPY . ./
---> Using cache
---> 631ca2773407
Step 4/5 : EXPOSE 80
---> Using cache
---> 94a50bb10fbe
Step 5/5 : ENTRYPOINT dotnet WebDockerCoreApp
---> Using cache
---> 7003460ebe84
Successfully built 7003460ebe84
Successfully tagged webdockercoreapp:latest
PS H:\DevAreaLocal\COMPANY - RAD PROJECTS\DockerApp\WebDockerCoreApp> docker inspect --format="{{.Id}}" 7003460ebe84
Got Bellow ID
sha256:7003460ebe84bdc3e8647d7f26f9038936f032de487e70fb4f1ca137f9dde737
If I run bellow command
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" 7003460ebe84
Got bellow response
Template parsing error: template: :1:19: executing "" at <.NetworkSettings.Net...>: map has no entry for key "NetworkSettings"
Docker.Compose.yml file settings
version: '2.1'
services:
webdockercoreapp:
image: webdockercoreapp
build:
context: ./WebDockerCoreApp
dockerfile: Dockerfile
ports:
- "5000:80"
networks:
default:
external:
name: nat
By runnging "docker network ls
"
got bellow response
NETWORK ID NAME DRIVER SCOPE
f04966f0394c nat nat local
3bcb5f906e01 none null local
680d4b4e1a0d webdockercoreapp_default nat local
When I run "docker network inspect webdockercoreapp_default
"
Got below response
[
{
"Name": "webdockercoreapp_default",
"Id": "680d4b4e1a0de228329986f217735e5eb35e9925fd04321569f9c9e78508ab88",
"Created": "2017-12-09T22:59:55.1558081+05:30",
"Scope": "local",
"Driver": "nat",
"EnableIPv6": false,
"IPAM": {
"Driver": "windows",
"Options": null,
"Config": [
{
"Subnet": "0.0.0.0/0",
"Gateway": "0.0.0.0"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {
"com.docker.network.windowsshim.hnsid": "ad817a46-e7ff-4fc7-9bb9-d6cf17820b8a"
},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "webdockercoreapp"
}
}
]
Change in command withing Docker file solve the issue. Bellow is the code snippet
Since we must build our project, this first container we create is a temporary container which we will use to do just that, and then discard it at the end.
Next, we copy over the .csproj files into our temporary container's '/app' directory. We do this because .csproj files contain contain a list of package references our project needs. After copying this file, dotnet will read from it and then to go out and fetch all of the dependencies and tools which our project needs.
Once we've pulled down all of those dependencies, we copy it into the temporary container. We then tell dotnet to publish our application with a release configuration and specify the output path.
We should have successfully compiled our project. Now we need to build our finalized container.
Our base image for this final container is similar but different to the FROM command above--it doesn't have the libraries capable of building an ASP.NET app, only running.
Concussion:
We have now successfully performed what is called a multi-stage build. We used the temporary container to build our image and then moved over the published dll into another container so that we minimized the footprint of the end result. We want this container to have the absolute minimum required dependencies to run; if we had kept with using our first image, then it would have come packaged with other layers (for building ASP.NET apps) which were not vital and therefore would increase our image size.
FROM microsoft/aspnetcore-build:1.1 AS build-env
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM microsoft/aspnetcore:1.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "CoreApiDockerSupport.dll"]
Put withing .dockerignore
file
bin\
obj\
Note: Above settings will work if you create a Asp.Net Core Project from Visual Studio IDE with in-build docker support (using docker-compose.yml
and docker-compose.ci.build.yml
) files or without it.