Building a Dockerfile on Windows 11 is a common workflow for containerized development. Here’s how you can do it—step by step:
1. Install Docker Desktop for Windows
- Go to the Docker Desktop download page.
- Download the Windows installer and run it.
- Follow the prompts (ensure “WSL2” support is selected, if available).
- NOTE: Windows 11 works best with WSL2.
2. Write Your Dockerfile
- Use a code editor (e.g., VS Code, Notepad++).
- Save your Dockerfile as simply named:
Dockerfile
(no extension). - Example (Python app):
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
3. Open a Terminal
- On Windows, you can use:
- Windows Terminal (
wt
command) - Command Prompt (
cmd
) - PowerShell
- WSL2 Terminal (Recommended)
4. Navigate to the Dockerfile Location
Use the cd
command to go to your project directory:
cd path\to\your\project
5. Build the Docker Image
Use the docker build
command. For example:
docker build -t my-app:latest .
-t my-app:latest
gives your image a name and tag (latest
).- The final
.
means “use the Dockerfile in the current directory”.
6. Run the Docker Container (Optional)
Test your image:
docker run --rm -it my-app:latest
7. Troubleshooting
- If Docker commands aren’t recognized, make sure Docker Desktop is running.
- Check Windows Terminal settings if using WSL2, and ensure file sharing is set up for your code folders.
Summary Table
Step | Command/Action |
---|---|
Install Docker | Download & install Docker Desktop |
Write Dockerfile | Use text editor, save as Dockerfile |
Open Terminal | PowerShell, CMD, WSL or Windows Terminal |
Go to directory | cd path\to\project |
Build image | docker build -t my-app:latest . |
Run container | docker run --rm -it my-app:latest |
Tip: You can use Docker Desktop’s GUI to see your images and containers as well!
Leave a Reply