Docker & Rancher Desktop Local Development Setup Guide - Yash-777/MyWorld GitHub Wiki

Docker & Rancher Desktop Local Development Setup Guide

Table of Contents

  1. What is Rancher Desktop?
  2. What is Docker?
  3. Installation & Setup
  4. Multi-Database Architecture
  5. MSSQL Server Setup
  6. MongoDB Setup
  7. Redis Setup
  8. Verification & Testing
  9. Common Errors & Solutions

What is Rancher Desktop?

Rancher Desktop is a lightweight, open-source container management platform that brings Docker desktop functionality to your local machine.

Key Benefits:

  • Free alternative to Docker Desktop Pro
  • Includes Kubernetes capability (optional)
  • Container runtime options (Docker or containerd)
  • Perfect for development and testing
  • Works on Windows, macOS, and Linux

When to Use:

  • Local development of containerized applications
  • Testing multi-container environments
  • CI/CD pipeline development
  • Microservices testing

What is Docker?

Docker is a containerization platform that packages your application and its dependencies into isolated containers.

Core Concepts:

  • Image: Blueprint/template (like a snapshot)
  • Container: Running instance of an image (like a VM, but lightweight)
  • Registry: Repository where images are stored (Docker Hub)
  • Dockerfile: Script that defines how to build an image

Docker allows each to run in an isolated container on your local machine without manual installation complexity.


Installation & Setup

Download and Install

  1. Download Rancher Desktop

  2. Launch Rancher Desktop

    • After installation, open Rancher Desktop
    • It will initialize the Docker environment
    • Monitor the status bar (usually takes 1-2 minutes on first run)
  3. Verify Installation

    • Open PowerShell or Command Prompt
    • If you use ConEmu64.exe, treat it as a Windows terminal emulator (tabs + split panes) for running Docker commands.
    • Run: docker --version
    • Expected: Docker version X.XX.X, build ...

Verify Docker Works

image Docker Hub - Hello World! github

# Test with a simple hello-world container
docker run hello-world

Expected output: "Hello from Docker!"

Ξ» docker run hello-world
                                                   
Unable to find image 'hello-world:latest' locally                               
latest: Pulling from library/hello-world                                        
4f55086f7dd0: Pull complete                                                     
d5e71e642bf5: Download complete                                                 
Digest: sha256:f9078146db2e05e794366b1bfe584a14ea6317f44027d10ef7dad65279026885 
Status: Downloaded newer image for hello-world:latest                           
                                                                                
Hello from Docker!                                                              
This message shows that your installation appears to be working correctly.      
                                                                                
To generate this message, Docker took the following steps:                      
 1. The Docker client contacted the Docker daemon.                              
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.       
    (amd64)                                                                     
 3. The Docker daemon created a new container from that image which runs the    
    executable that produces the output you are currently reading.              
 4. The Docker daemon streamed that output to the Docker client, which sent it  
    to your terminal.                                                           
                                                                                
To try something more ambitious, you can run an Ubuntu container with:          
 $ docker run -it ubuntu bash                                                   
                                                                                
Share images, automate workflows, and more with a free Docker ID:               
 https://hub.docker.com/                                                        
                                                                                
For more examples and ideas, visit:                                             
 https://docs.docker.com/get-started/                                           
Ξ» docker images hello-world
IMAGE                ID             DISK USAGE   CONTENT SIZE   EXTRA
hello-world:latest   f9078146db2e       25.9kB         9.49kB    U

Multi-Database Architecture

This service uses three complementary databases:

Database Purpose Port Image
MSSQL (SQL Server 2019) Relational data (JPA/Hibernate) 1433 mcr.microsoft.com/mssql/server:2019-latest
MongoDB Document store for bookings/appointments 27017 mongo:latest
Redis In-memory cache and data store (@RedisHash) 6379 redis:latest

All three can run simultaneously on your local machine.


MSSQL Server Setup

Understanding the Images

There are two separate MSSQL images:

  • mcr.microsoft.com/mssql/server:2019-latest β†’ SQL Server engine (database server)
  • mcr.microsoft.com/mssql-tools β†’ sqlcmd client tools (command-line access)

You need the server image to start the database, and the tools image to run commands.


Step 1: Start MSSQL Container

docker run -e "ACCEPT_EULA=Y" `
  -e "MSSQL_SA_PASSWORD=Strong@123" `
  -p 1433:1433 `
  --name mssql `
  -d `
  mcr.microsoft.com/mssql/server:2019-latest

Command Explanation:

  • docker run β†’ Create and start a new container
  • -e "ACCEPT_EULA=Y" β†’ Accept SQL Server license agreement (required)
  • -e "MSSQL_SA_PASSWORD=Strong@123" β†’ Set SA (admin) password
  • -p 1433:1433 β†’ Map port 1433 (host:container)
  • --name mssql β†’ Container name (reference for later commands)
  • -d β†’ Detached mode (runs in background)
  • mcr.microsoft.com/mssql/server:2019-latest β†’ Image name and version

Expected Output:

acc164ea3b4205b6ff5988f0276756ff7d216ca2be9e05fdb6008bae93331fe0

(This is the container ID)


Step 2: Verify Container Is Running

docker ps

Expected Output:

CONTAINER ID   IMAGE                                      CREATED         STATUS        PORTS
acc164ea3b42   mcr.microsoft.com/mssql/server:2019-latest  2 minutes ago   Up 2 minutes   0.0.0.0:1433->1433/tcp

Step 3: Create Database (finance)

docker run -it --rm `
  mcr.microsoft.com/mssql-tools `
  /opt/mssql-tools/bin/sqlcmd `
  -S host.docker.internal,1433 `
  -U sa `
  -P "Strong@123" `
  -Q "CREATE DATABASE finance"

Command Explanation:

  • docker run -it --rm β†’ Run container interactively and remove after exit
  • mcr.microsoft.com/mssql-tools β†’ Use the tools image (for sqlcmd)
  • /opt/mssql-tools/bin/sqlcmd β†’ SQL command utility (path inside container)
  • -S host.docker.internal,1433 β†’ Connect to MSSQL on this host/port (special hostname for Docker on Windows)
  • -U sa β†’ Username (SA = System Administrator)
  • -P "Strong@123" β†’ Password
  • -Q "CREATE DATABASE finance" β†’ SQL query to execute

Note: -it --rm ensures the temporary container is cleaned up after the command finishes.


Step 4: Verify Database Creation

docker run -it --rm `
  mcr.microsoft.com/mssql-tools `
  /opt/mssql-tools/bin/sqlcmd `
  -S host.docker.internal,1433 `
  -U sa `
  -P "Strong@123" `
  -Q "SELECT name FROM sys.databases"

Expected Output:

name
-------
master
tempdb
model
msdb
finance

(5 rows affected)

The finance database should now appear in the list.


Stopping and Removing MSSQL Container

If you need to stop/restart:

# Stop the container
docker stop mssql

# Remove the container
docker rm mssql

# Then restart from Step 1 if needed

MongoDB Setup

Step 1: Start MongoDB Container

docker run -d `
  --name mongodb `
  -p 27017:27017 `
  mongo:latest

Command Explanation:

  • docker run -d β†’ Run in detached mode (background)
  • --name mongodb β†’ Container name
  • -p 27017:27017 β†’ Map MongoDB port
  • mongo:latest β†’ Official MongoDB image

Expected Output:

b90f57458ca512345abcd...

Step 2: Verify MongoDB Is Running

docker ps | findstr mongodb

Expected Output:

CONTAINER ID   IMAGE         CREATED        STATUS        PORTS
b90f57458ca5   mongo:latest  2 hours ago    Up 2 hours    0.0.0.0:27017->27017/tcp   mongodb

Step 3: Test MongoDB Connection

docker exec -it mongodb mongosh

Expected Output:

mongosh 6.0.0
connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh
Type "help" for help
test>

Exit with: exit


MongoDB Note for Spring Application

In application-dev.properties, MongoDB connection is typically:

spring.data.mongodb.uri=mongodb://localhost:27017/mongoDBCollection
spring.data.mongodb.database=mongoDBCollection

MongoDB runs with no authentication by default in development mode.


Redis Setup

Understanding Redis Dependency

In pom.xml, this dependency only provides the Redis client:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

It does NOT install Redis server. You must run Redis in a container.


Step 1: Start Redis Container

docker run -d `
  --name redis `
  -p 6379:6379 `
  redis:latest

Command Explanation:

  • docker run -d β†’ Detached mode
  • --name redis β†’ Container name
  • -p 6379:6379 β†’ Map Redis port
  • redis:latest β†’ Official Redis image

Expected Output:

9279c7188c8719739904835ed6563c9d502d5fc0fe58fccf48a730acad03b83f

Step 2: Verify Redis Is Running

docker ps | findstr redis

Expected Output:

CONTAINER ID   IMAGE         CREATED         STATUS        PORTS
9279c7188c87   redis:latest  2 minutes ago   Up 2 minutes  0.0.0.0:6379->6379/tcp   redis

Step 3: Test Redis Connection

docker exec -it redis redis-cli ping

Expected Output:

PONG

Redis Note for Spring Application

In application-dev.properties:

spring.redis.host=127.0.0.1
spring.redis.port=6379
# No authentication in dev mode by default

Verification & Testing

All Containers Running at Once

docker ps

Expected Output:

CONTAINER ID   IMAGE                                      STATUS        PORTS
acc164ea3b42   mcr.microsoft.com/mssql/server:2019-latest  Up 2 hours    0.0.0.0:1433->1433/tcp     mssql
b90f57458ca5   mongo:latest                                Up 2 hours    0.0.0.0:27017->27017/tcp   mongodb
9279c7188c87   redis:latest                                Up 2 hours    0.0.0.0:6379->6379/tcp     redis

All three should be Up.


Quick Health Check Script

Run all three tests in sequence:

# Test MSSQL
docker run -it --rm mcr.microsoft.com/mssql-tools /opt/mssql-tools/bin/sqlcmd -S host.docker.internal,1433 -U sa -P "Strong@123" -Q "SELECT 1"
echo "MSSQL OK"

# Test MongoDB
docker exec -it mongodb mongosh --eval "db.adminCommand('ping')" > $null 2>&1
echo "MongoDB OK"

# Test Redis
docker exec -it redis redis-cli ping > $null 2>&1
echo "Redis OK"

Sample output from your environment:

C:\Users\ymerugu
Ξ» docker run -it --rm mcr.microsoft.com/mssql-tools /opt/mssql-tools/bin/sqlcmd -S host.docker.internal,1433 -U sa -P "Strong@123" -Q "SELECT 1"

-----------
          1

(1 rows affected)

C:\Users\ymerugu
Ξ» docker exec -it mongodb mongosh --eval "db.adminCommand('ping')" > $null 2>&1

C:\Users\ymerugu
Ξ» docker exec -it redis redis-cli ping > $null 2>&1

Common Errors & Solutions

Error 1: Cannot Connect to MSSQL (Login Failed)

Error Message:

Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login failed for user 'sa'.

Cause: Wrong hostname or MSSQL container not ready yet.

Solution:

  1. Use host.docker.internal on Windows (not localhost or 127.0.0.1)
  2. Wait 10-15 seconds after starting the container (MSSQL takes time to initialize)
  3. Verify container is running: docker ps | findstr mssql

Correct Command:

docker run -it --rm mcr.microsoft.com/mssql-tools /opt/mssql-tools/bin/sqlcmd -S host.docker.internal,1433 -U sa -P "Strong@123" -Q "SELECT 1"

Error 2: Cannot Find /opt/mssql-tools/bin/sqlcmd

Error Message:

OCI runtime exec failed: exec failed: unable to start container process: 
exec: "/opt/mssql-tools/bin/sqlcmd": stat /opt/mssql-tools/bin/sqlcmd: no such file or directory

Cause: Trying to run sqlcmd inside the MSSQL server container instead of the tools container.

Wrong Way:

docker exec -it mssql /opt/mssql-tools/bin/sqlcmd ...  # ❌ WRONG

Correct Way:

docker run -it --rm mcr.microsoft.com/mssql-tools /opt/mssql-tools/bin/sqlcmd ...  # βœ… RIGHT

The mssql-tools image has sqlcmd; the server image does not.


Error 3: Redis Connection Failed in Spring Application

Error Message:

org.springframework.data.redis.RedisConnectionFailureException: 
Unable to connect to Redis; nested exception is 
io.lettuce.core.RedisConnectionException: Unable to connect to 127.0.0.1/<unresolved>:6379

Cause: Redis container is not running.

Solution:

# Check if Redis is running
docker ps | findstr redis

# If not running, start it
docker run -d --name redis -p 6379:6379 redis

# Test connection
docker exec -it redis redis-cli ping

Error 4: Port Already in Use

Error Message:

docker: Error response from daemon: driver failed programming external connectivity 
on endpoint xyz: Bind for 0.0.0.0:1433 failed: port is already allocated.

Cause: Another service or container is using the port.

Solution:

# Option 1: Stop the existing container
docker stop <container-name>

# Option 2: Use a different port (map to different host port)
docker run -p 1434:1433 ... # Use 1434 instead of 1433 on host

# Option 3: Check what's using the port (Windows)
netstat -ano | findstr :1433

Error 5: MSSQL Container Exits Immediately

Error Message:

docker ps  # Container shows "Exited" status

Cause: Usually missing EULA acceptance or bad password format.

Solution:

# Correct log commands (Windows)
docker logs --tail 100 mssql
docker logs -f --tail 100 mssql

# Ensure command has both EULA and PASSWORD
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Strong@123" -p 1433:1433 --name mssql -d mcr.microsoft.com/mssql/server:2019-latest

If you run docker logs mssql tail -n 1000 -f, Docker returns:

docker: 'docker logs' requires 1 argument

Because tail -n 1000 -f must be passed as Docker options, not trailing shell args.


Quick Reference Commands

View All Running Containers

docker ps

View All Containers (including stopped)

docker ps -a

View Container Logs

docker logs --tail 100 <container-name>
docker logs -f --tail 100 mssql  # Follow logs in real-time

Stop All Containers

docker stop $(docker ps -q)

Remove All Containers

docker rm $(docker ps -aq)

Check Container Resource Usage

docker stats

Access Container Shell

docker exec -it <container-name> /bin/bash

Spring Boot Application Configuration

application-dev.properties Database Settings

# MSSQL (SQL Server 2019)
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=finance;
spring.datasource.username=sa
spring.datasource.password=Strong@123
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver

# MongoDB
spring.data.mongodb.uri=mongodb://localhost:27017/mongoDBCollection
spring.data.mongodb.database=mongoDBCollection

# Redis
spring.redis.host=localhost
spring.redis.port=6379

Troubleshooting Workflow

  1. Check all containers are running:

    docker ps
  2. If container not running, start it:

    docker start <container-name>
  3. Check logs for errors:

    docker logs --tail 100 <container-name>
  4. Test connection:

    • MSSQL: docker run -it --rm mcr.microsoft.com/mssql-tools /opt/mssql-tools/bin/sqlcmd -S host.docker.internal,1433 -U sa -P "Strong@123" -Q "SELECT 1"
    • MongoDB: docker exec -it mongodb mongosh --eval "db.adminCommand('ping')"
    • Redis: docker exec -it redis redis-cli ping
  5. If still failing, remove and recreate:

    docker stop <container-name>
    docker rm <container-name>
    # Then run docker run command again

Summary Checklist

  • Rancher Desktop installed and running
  • docker --version returns version number
  • MSSQL container running on port 1433
  • MongoDB container running on port 27017
  • Redis container running on port 6379
  • All three connections tested successfully
  • application-dev.properties updated with correct connection strings
  • Spring Boot application starts without database connection errors
⚠️ **GitHub.com Fallback** ⚠️