Docker Desktop on Windows: A Full Guide

Docker Desktop on Windows: A Full Guide

Docker Desktop brings the power of containerization to your Windows machine, simplifying app development and deployment. This guide covers everything you need to get started, from installation to managing containers, ports, and troubleshooting.

Installation:

  1. Download: Head to https://docs.docker.com/desktop/install/windows-install/ and download the latest installer.
  2. Run: Double-click the installer and follow the on-screen instructions. Ensure “Use WSL 2 based engine” is selected for better performance.
  3. Restart: Once installed, restart your computer.

Basic Commands:

  • Start:
    • Open Docker Desktop’s whale icon in the taskbar menu.
    • Click “Containers” and choose your desired container to start it.
  • Stop:
    • In the “Containers” section, click the “Stop” button next to the running container.
  • Remove:
    • Select the stopped container and click “Delete.”
    • To remove an unused image, run docker image rm <image_name> in PowerShell.

Port Forwarding:

  1. Dockerfile: Specify the desired port mapping in your Dockerfile using EXPOSE <port>.
  2. Run command: When running the container, use the -p flag: docker run -p <host_port>:<container_port> <image_name>.
    • Example: docker run -p 8080:80 mywebserver exposes the container’s port 80 (web server) to your host machine’s port 8080.

General Commands:

  • docker version: Checks the Docker version.
  • docker info: Displays information about the Docker daemon.
  • docker help: Provides help on available commands and their usage.

Image Management:

  • docker images: Lists all local Docker images.
  • docker pull <image_name>: Downloads an image from a registry (e.g., Docker Hub).
  • docker build: Builds an image from a Dockerfile.
  • docker push <image_name>: Pushes an image to a registry.
  • docker image rm <image_name>: Removes an image.

Container Management:

  • docker run <image_name>: Runs a container from an image.
  • docker ps: Lists all running containers.
  • docker stop <container_name>: Stops a running container.
  • docker rm <container_name>: Removes a stopped container.
  • docker exec -it <container_name> bash: Starts an interactive shell session inside a container.
  • docker logs <container_name>: Displays the logs of a container.
See also  Running VirtualBox in Windows 11

Network Management:

  • docker network ls: Lists all available networks.
  • docker network create <network_name>: Creates a new network.
  • docker run -d --network <network_name> <image_name>: Runs a container in a specific network.

Volume Management:

  • docker volume ls: Lists all volumes.
  • docker volume create <volume_name>: Creates a new volume.
  • docker run -v <volume_name>:<container_path> <image_name>: Mounts a volume into a container.

Additional Commands:

  • docker login: Logs in to a Docker registry.
  • docker search <term>: Searches for images on Docker Hub.
  • docker compose: Manages multi-container applications.

Troubleshooting:

  • Docker not starting: Check WSL 2 status and enable it if necessary. Look for error messages in Docker Desktop settings.
  • Connection issues: Restart Docker Desktop and ensure firewall rules allow Docker traffic.
  • Network errors: Verify host and container port mappings are correct. Check for conflicts with other applications using the same ports.
  • Resource limitations: Increase Docker Desktop’s memory and CPU allocation in settings if containers struggle to run.

Additional Resources:

Tips:

  • Use Docker Compose for managing multiple containers and their dependencies.
  • Explore Docker Hub for pre-built images to avoid building everything from scratch.
  • Leverage Docker volumes to persist data outside containers for easier sharing and persistence.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.