Introduction
Use Docker to build consistent environments for development, education, and communication.
- Developer: Achieve a unified environment, simplifying version control and deployment.
- Educator: Provide an identical environment for all students, easing material distribution and hands-on support.
- Communicator: Ensure a consistent setup for study groups and technical discussions.
Quick Start
-
Clean up Docker (if needed)
View OS-specific commands
Linux/macOS:
sudo docker system prune
Windows (PowerShell):
docker system prune
-
Download environment files
Download environment files from codeindocker.com by selecting your target and clicking the zip button. -
Extract and move to folder
View OS-specific commands
Linux/macOS:
unzip docker_files.zip -d docker_folder && cd ./docker_folder
Windows (PowerShell):
Expand-Archive -Path docker_files.zip -DestinationPath docker_folder
cd docker_folder
-
Run setup
Click the setup button on the website, copy the provided command, paste it into your terminal, and run it.
This command automatically builds the Docker images and starts the containers. -
Check and access containers
sudo docker ps
To access a container:
sudo docker exec -it [container_name] bash
Writing Dockerfile
A Dockerfile defines the container's operating environment. It's crucial to include your project's git URI (remote repository address) in a git clone
command within the Dockerfile. This ensures your source code is automatically downloaded when the Docker image is built.
Example:
FROM python:3.11
# Install basic tools
RUN apt-get update && apt-get install -y \
git \
curl \
wget \
sudo \
sqlite3 \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /apps
# Change to your own git URI!
RUN git clone -b main https://github.com/yojulab/learn_RAGs learn_RAGs
WORKDIR /apps/learn_RAGs
RUN python -m pip install --upgrade pip
RUN python -m pip install --no-cache-dir -r ./requirements.txt
RUN rm -rf .git
For detailed Dockerfile instructions, refer to the official Docker documentation.
Writing docker-compose.yml
A docker-compose.yml file is used to define and manage multi-container Docker applications. It simplifies the orchestration of services, networks, and volumes.
Below is a basic example:
services:
devs:
build:
context: .
command: sleep infinity
# db_mongodb:
# image: mongo:7
# restart: always
# ports:
# - 27017:27017
# command: mongod --bind_ip 0.0.0.0
For docker-compose options and details, see the official documentation.
Run & Check
- Build images and run containers
docker-compose up --build -d
- Check running containers
docker ps
- Access a container
docker exec -it [container_name] bash
If you encounter issues, refer to the Docker Getting Started Guide.
Docker Files for Project Registration
Learn how to automatically generate Docker files for sharing and registering team projects. This process uses MCP server with prompts to analyze your project folder and create the necessary Docker files.
1. Installing MCP Server
First, install the Model Context Protocol (MCP) server which will analyze your project and generate Docker files.
For installation instructions, visit: MCP Servers GitHub Repository
# Basic installation (after following the repository instructions)
git clone https://github.com/modelcontextprotocol/servers.git
cd servers
# Follow the setup instructions in the README
2. Creating Basic Folder Structure
Create a ./dockers
folder in your project root directory to store the generated Docker files.
mkdir -p ./dockers
cd ./dockers
3. Using MCP Server with Prompts
Use the MCP server with specific prompts to automatically analyze your project and generate Docker files.
# Start the MCP server (if not already running)
mcp-server start
# Send a prompt to analyze your project and generate Docker files
mcp-client prompt "Analyze my project at /path/to/project and generate Docker files in ./dockers folder. \
The project uses git for source code management. Include Dockerfile and docker-compose.yml. \
Make sure to use git clone to fetch the source code from the repository."
4. Customizing Generated Files
After the MCP server generates the Docker files, you can customize them with additional prompts.
# Example prompt for customizing Dockerfile
mcp-client prompt "Review the Dockerfile in ./dockers and optimize it for a Python FastAPI application. \
Make sure it includes git clone from my repository at https://github.com/username/project.git \
and properly installs all dependencies from requirements.txt."
# Example prompt for customizing docker-compose.yml
mcp-client prompt "Update the docker-compose.yml in ./dockers to include a MySQL database service \
and configure proper networking between the application and database."
5. Example Generated Files
The MCP server will generate files similar to these examples:
Dockerfile:
FROM python:3.11
# Install basic tools
RUN apt-get update && apt-get install -y \
git \
curl \
wget \
sudo \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /apps
# Clone source code from git repository
RUN git clone -b main https://github.com/username/project.git project
WORKDIR /apps/project
# Install dependencies
RUN python -m pip install --upgrade pip
RUN python -m pip install --no-cache-dir -r ./requirements.txt
# Additional configuration
EXPOSE 8000
# Optional startup command
# CMD ["python", "app.py"]
docker-compose.yml:
version: '3'
services:
# Backend service (e.g., FastAPI)
backend:
build:
context: ./backend
ports:
- "8000:8000"
volumes:
- ./backend/app:/app
depends_on:
- db
environment:
- DATABASE_URL=mysql://user:password@db:3306/dbname
command: uvicorn main:app --host 0.0.0.0 --port 8000 --reload
# Frontend service (e.g., Spring Boot)
frontend:
build:
context: ./frontend
ports:
- "8080:8080"
volumes:
- ./frontend/src:/app/src
depends_on:
- backend
# Database service (e.g., MySQL)
db:
image: mysql:8.0
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- MYSQL_DATABASE=dbname
- MYSQL_USER=user
- MYSQL_PASSWORD=password
volumes:
- mysql_data:/var/lib/mysql
volumes:
mysql_data:
6. Reference Projects
Check these GitHub repositories for real-world examples:
7. Testing and Submission
Test your generated Docker files and submit them for project registration.
# Test the Docker setup
cd ./dockers
docker-compose up --build
# After confirming everything works, submit to the project registration page