-
Notifications
You must be signed in to change notification settings - Fork 0
Home
| Title | Remark/Code |
|---|---|
| Setup | Setup Docker on your PC |
| Basic Commands | Learn essential Docker commands |
| Building Images | Guide to creating and managing Docker images |
| Running Containers | Learn how to run and manage containers |
| Dockerfile Guide | Step-by-step guide to writing a Dockerfile |
| Docker Compose | How to manage multi-container applications |
| Volumes | Using Docker volumes for persistent data storage |
| Networking | Guide to setting up Docker container networks |
| Pushing Images to Docker Hub | Share your Docker images on Docker Hub |
| Advanced Features | Multi-stage builds and optimization techniques |
π΄ Windows 10/11 Home β β Does not support Windows Containers
π If youβre on Home edition, you can only use Linux containers, so WPF apps (which are Windows-only) cannot be containerized with your current OS. Docker Desktop disables that feature on Home Edition.
You already have:
ConvertImageToBase64.sln
βββ ConvertImageToBase64.Lib β
your reusable logic
βββ ConvertImageToBase64.App β WPF app β now weβll replace with Console app
From the root:
dotnet new console -n ConvertImageToBase64.ConsoleYou now have:
ConvertImageToBase64.Console/
βββ Program.cs
dotnet sln add ConvertImageToBase64.Console/ConvertImageToBase64.Console.csprojdotnet add ConvertImageToBase64.Console/ConvertImageToBase64.Console.csproj reference ConvertImageToBase64.Lib/ConvertImageToBase64.Lib.csprojIf itβs not already done, move logic like:
public static class ImageConverter
{
public static string ConvertToBase64(string imagePath)
{
byte[] bytes = File.ReadAllBytes(imagePath);
return Convert.ToBase64String(bytes);
}
}into ConvertImageToBase64.Lib β for example in ImageConverter.cs.
Here's a simple usage:
using System;
using ConvertImageToBase64.Lib;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the path of the image:");
string path = Console.ReadLine();
if (File.Exists(path))
{
string base64 = ImageConverter.ConvertToBase64(path);
Console.WriteLine("Base64:");
Console.WriteLine(base64);
}
else
{
Console.WriteLine("File not found.");
}
}
}dotnet run --project ConvertImageToBase64.ConsoleIf you no longer need it:
dotnet sln remove ConvertImageToBase64.App/ConvertImageToBase64.App.csprojThen delete the folder manually.
Assume this folder layout:
ConvertImageToBase64/
βββ ConvertImageToBase64.Console/ β Console app
β βββ ConvertImageToBase64.Console.csproj
βββ ConvertImageToBase64.Lib/ β Class Library
β βββ ConvertImageToBase64.Lib.csproj
βββ ConvertImageToBase64.sln
βββ Dockerfile β We will create this now
Paste this into a file named Dockerfile:
# Stage 1: Build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
# Copy solution and projects
COPY *.sln .
COPY ConvertImageToBase64.Console/*.csproj ./ConvertImageToBase64.Console/
COPY ConvertImageToBase64.Lib/*.csproj ./ConvertImageToBase64.Lib/
# Restore dependencies
RUN dotnet restore
# Copy all source code
COPY ConvertImageToBase64.Console/. ./ConvertImageToBase64.Console/
COPY ConvertImageToBase64.Lib/. ./ConvertImageToBase64.Lib/
# Build the app
RUN dotnet publish ConvertImageToBase64.Console -c Release -o out
# Stage 2: Runtime
FROM mcr.microsoft.com/dotnet/runtime:6.0
WORKDIR /app
COPY --from=build /app/out ./
ENTRYPOINT ["dotnet", "ConvertImageToBase64.Console.dll"]In your terminal at the root of the solution:
docker build -t convertimagebase64 .To run it and interact:
docker run -it --rm convertimagebase64It'll prompt you to enter the path to an image. If you're working with local files, you'll need to mount a volume.
If you want your container to access images from your host machine:
docker run -it --rm -v "C:\Users\you\Pictures:/images" convertimagebase64Then inside the app, enter something like:
/images/my-image.png
In WSL, try this:
sudo mkdir /mnt/g
sudo mount -t drvfs G: /mnt/gπ‘ This uses
drvfsβ the Windows-to-WSL filesystem bridge.
If that works, then try:
ls /mnt/gYou should see your GitHub folders π
Now your Docker volume mount will work:
docker run -it --rm -v "/mnt/g/GitHub/ConvertImageToBase64/ConvertImageToBase64.Tests/Images:/data" convertimagebase64When prompted:
Enter the path of the image:
/data/image.png
To avoid doing this manually every time:
-
Run:
sudo nano /etc/wsl.conf
-
Add this:
[automount] enabled = true mountFsTab = false
-
Save, then restart WSL:
wsl --shutdown
Assuming your image is named convertimagebase64, you need to tag it with your Docker Hub username.
docker tag convertimagebase64 yourdockerhubusername/convertimagebase64:latestExample (if your Docker Hub username is lucyberry):
docker tag convertimagebase64 lucyberry/convertimagebase64:latestdocker loginEnter your Docker Hub username and password (or personal access token if 2FA is enabled).
docker push yourdockerhubusername/convertimagebase64:latestIt will upload the image layers to your Docker Hub repo.
You can now use it anywhere with:
docker run yourdockerhubusername/convertimagebase64- Go to https://hub.docker.com
- Click on Repositories > Create Repository
- Name it
convertimagebase64 - Leave visibility as public or private
- Then push the image as shown above