Skip to content

Instantly share code, notes, and snippets.

@aleor
Last active April 20, 2018 16:32
Show Gist options
  • Save aleor/6d2b1911ab8f0a5596a78da246c888f5 to your computer and use it in GitHub Desktop.
Save aleor/6d2b1911ab8f0a5596a78da246c888f5 to your computer and use it in GitHub Desktop.
Docker memo note
Build image:
docker build -t myimage/name .
List images:
docker image ls
Run image with publishing ports on host:
docker run --rm -it -p 8080:80 myimage/name
Look inside the container:
docker inspect
### Intermdediate containers ###
Skip removing of intermediate containers:
docker build -t tagName --rm=false --no-cache .
List intermediate containers:
docker ps -a
Check file-system changes for each intermediate container:
docker diff #container-id
###
### Dockerfiles ###
-------------------------------
Dockerfile to run published on the host
FROM microsoft/aspnetcore:2
WORKDIR /
COPY bin/Release/netcoreapp2.0/publish .
ENTRYPOINT ["dotnet", "appQuiz.dll"]
----------------------------------
Dockerfile supporting build in container:
FROM microsoft/aspnetcore-build:2
WORKDIR /api
COPY . .
RUN dotnet restore
RUN dotnet publish -o /publish
WORKDIR /publish
ENTRYPOINT ["dotnet", "/publish/api.dll"]
---------------------------------------
Build it:
docker build -t aspnetcore/api:build .
Run it:
docker run --rm -it -p 8080:80 aspnetcore/api:build
----------------------------------------
Multi-stage Dockerfile (optimized)
# Build Stage
FROM microsoft/aspnetcore-build:2 AS build-env
WORKDIR /api
COPY api.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -o /publish
# Runtime Image Stage
FROM microsoft/aspnetcore:2
WORKDIR /publish
COPY --from=build-env /publish .
ENTRYPOINT ["dotnet", "api.dll"]
----------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment