text stringlengths 0 13.4k |
|---|
FROM microsoft/dotnet:2.0-runtime AS runtime |
ENV ASPNETCORE_URLS http://+:80 |
WORKDIR /app |
COPY --from=build /app/AspNetCoreTodo/out ./ |
ENTRYPOINT ["dotnet", "AspNetCoreTodo.dll"] |
The FROM command is used again to select a smaller image that only has |
the dependencies needed to run the application. The ENV command is |
used to set environment variables in the container, and the |
ASPNETCORE_URLS environment variable tells ASP.NET Core which |
network interface and port it should bind to (in this case, port 80). |
The ENTRYPOINT command lets Docker know that the container should |
be started as an executable by running dotnet AspNetCoreTodo.dll . This |
tells dotnet to start up your application from the compiled file created |
by dotnet publish earlier. (When you do dotnet run during |
development, you're accomplishing the same thing in one step.) |
The full Dockerfile looks like this: |
Dockerfile |
FROM microsoft/dotnet:2.0-sdk AS build |
COPY AspNetCoreTodo/*.csproj ./app/AspNetCoreTodo/ |
WORKDIR /app/AspNetCoreTodo |
RUN dotnet restore |
COPY AspNetCoreTodo/. ./ |
RUN dotnet publish -o out /p:PublishWithAspNetCoreTargetManifest=" |
false" |
FROM microsoft/dotnet:2.0-runtime AS runtime |
120 |
Deploy with Docker |
ENV ASPNETCORE_URLS http://+:80 |
WORKDIR /app |
COPY --from=build /app/AspNetCoreTodo/out ./ |
ENTRYPOINT ["dotnet", "AspNetCoreTodo.dll"] |
Create an image |
Make sure the Dockerfile is saved, and then use docker build to create |
an image: |
docker build -t aspnetcoretodo . |
Don't miss the trailing period! That tells Docker to look for a Dockerfile |
in the current directory. |
Once the image is created, you can run docker images to to list all the |
images available on your local machine. To test it out in a container, run |
docker run --name aspnetcoretodo_sample --rm -it -p 8080:80 aspnet |
coretodo |
The -it flag tells Docker to run the container in interactive mode |
(outputting to the terminal, as opposed to running in the background). |
When you want to stop the container, press Control-C. |
Remember the ASPNETCORE_URLS variable that told ASP.NET Core to |
listen on port 80? The -p 8080:80 option tells Docker to map port 8080 |
on your machine to the container's port 80. Open up your browser and |
navigate to http://localhost:8080 to see the application running in the |
container! |
Set up Nginx |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.