| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Image: build of an app Container: instance of a build
Docker needs Hyper-V (needs to disable VirtualBox)
check Hyper-V Manager
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-AllHyper-V for Docker needed Hyper-V Manager
bcdedit /set hypervisorlaunchtype off (deactivate Hyper-V)
bcdedit /set hypervisorlaunchtype auto (reactivate Hyper-V)reboot
press info-button to activate hyper-v when docker starts
https://learn.microsoft.com/en-us/windows/wsl/install-manual
dockerfile = Recipe to create a docker image
simple Dockerfile
FROM node:latest
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 3000
ENTRYPOINT ["node", "app.js"]Run dockerfile
docker build .
build image (use slash as namespace separator)
Create hello World node app: https://medium.com/@adnanrahic/hello-world-app-with-node-js-and-express-c1eb7cfa8a30
docker build -t <image-name> .
example:
docker build -t bopa/node:latest .
show all images
docker images
BEWARE: delete image
docker image rm <name>
or
docker rmi <container>
BEWARE: Remember, you should remove all the containers before removing all the images from which those containers were created.
BEWARE: To delete all the images, run this:
docker rmi -f $(docker images -a -q)Delete all unused images
docker image prune
Get information - A Software Bill Of Materials (SBOM)
docker sbom <image name>
Start container
docker run -p 8000:3000 <image-name>
example:
docker run -p 8000:3000 bopa/node
App will run on Port 8000 (3000 is internal port)
Stop all containers (bash)
docker stop $(docker ps -a -q)BEWARE: To delete all containers including its volumes use (in bash)
docker rm -vf $(docker ps -a -q)Remove container by container-name
docker rm $(docker stop $(docker ps -a -q --filter name=containerName1 --format="{{.ID}}"))Delete all unused containers
docker container prune
Volumes or data volumes is a way for us to create a place in the host machine where we can write files so they are persisted.
Create
docker volume create <name of volume>
List
docker volume ls
Inspect
docker inspect <name of volume or container>
Find IP address:
docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" <containername>
Delete
docker volume rm <name of volume>
Delete all unused volumes
docker volume prune
docker exec -it <containername> bash
BEWARE: delete everything
docker system prune -afDetails/Source: https://github.com/docker/getting-started
Clone:
git clone https://github.com/docker/getting-started.gitBuild:
cd getting-started
docker build -t docker101tutorial .Run:
docker run -d -p 80:80 \ --name docker-tutorial docker101tutorialRun detached container with port mapping
docker run -d -p 8888:80 --name container-name> <image-name>Pull/Push to docker hub
docker pull <dockerhubuser>/<imagename>[:tag]
docker push <dockerhubuser>/<imagename>Pull/Push to a registry
docker pull <registry>/<url>[:tag]
docker push <registry>/<url>List all available tags:
docker pull -a <registry>/<url>Share: (optional)
docker tag docker101tutorial {userName}/docker101tutorial
docker push {userName}/docker101tutorialStart:
Press the play button in your desktop app.
If you are running a webserver on localhost (like IIS), you have to stop it first. Otherwise the container won't start.
http://localhost/
Continue this Tutorial in the Browser now.
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
</PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>Compare: build inside vs. build outside container: https://docs.docker.com/samples/dotnetcore/
https://docs.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019
Create new WebApi project in Visual Studio, option [x] Enable Docker checked
Empty WebApi Project contains WeatherForecast Controller and this Dockerfile:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR "/src/WebApplication1"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
Make sure, app is running in 'Docker' (not Kestrel, not IISExpress) and press F5.
While app is running in Docker now, you are even able to debug the app. (set a breakpoint to confirm)
Go to folder of csproj and build the container
docker build -t bopa/aspnetcore_windows -f Dockerfile ..
Start the container
docker run -p 8001:80 bopa/aspnetcore_windows
Test WebApi: http://localhost:8001/weatherforecast
Go to folder of csproj and build the container
docker build -t bopa/aspnetcore_linux -f Dockerfile ..
Start the container
docker run -p 8002:80 bopa/aspnetcore_linux
Test WebApi: http://localhost:8002/weatherforecast
| Back | FazBrowse Home | New Git URL |