Docker Development Setup
Using Docker for development ensures a consistent environment across different platforms and simplifies dependency management for the Linux C++ Backend Development Playground.
Why Docker?
The Docker development environment provides:
- Consistent development environment regardless of your host OS (macOS, Windows, Linux)
- Pre-installed development tools (g++, CMake, build-essential, Boost, OpenSSL, etc.)
- Isolated environment preventing conflicts with your system installations
- Easy switching between different project branches without dependency issues
Docker Commands Reference
The project provides convenient scripts for Docker development:
# Build Docker image
./scripts/docker-dev.sh build
# Start container (detached mode)
./scripts/docker-dev.sh run
# Enter running container
./scripts/docker-dev.sh exec
# Stop container
./scripts/docker-dev.sh stop
# Clean up containers and volumes
./scripts/docker-dev.sh clean
Building and Running Individual Phases
Once inside the container, you can build and run specific projects:
# Enter the container
./scripts/docker-dev.sh exec
# Navigate to project root
cd /app
# Build the entire project
mkdir -p build && cd build
cmake ..
make -j4
# Run specific executables (examples)
./build/phase1/cli-tools/my_ls [options]
./build/phase1/cli-tools/my_grep [options]
./build/phase1/cli-tools/my_wc [options]
Development Workflow Inside Container
-
Enter the container:
./scripts/docker-dev.sh exec -
Navigate to the project directory:
cd /app -
Create or modify source files in your host system (the
/appdirectory is mounted) -
Compile inside the container:
cd build
make -j4 -
Run executables:
./path/to/executable
Debugging with GDB
The development container comes with debugging tools:
# Inside the container
cd /app/build
# Compile with debug symbols
cmake -DCMAKE_BUILD_TYPE=Debug ..
make -j4
# Run with GDB
gdb ./path/to/executable
Running Tests
Execute the project tests using the provided script:
# Run tests (uses build-test directory)
./scripts/docker-dev.sh test
Visual Studio Code Integration
For the best development experience with Docker and VS Code:
- Install the "Remote - Containers" extension
- Open the project folder in VS Code
- Press
Ctrl+Shift+P(orCmd+Shift+Pon macOS) and select "Remote-Containers: Reopen in Container" - VS Code will build and connect to the development container
- You can then develop, build, and debug from within the container environment
Troubleshooting
Common Issues
-
Permission denied errors: Make sure Docker is running and you have proper permissions to run Docker commands.
-
Container won't start: Try cleaning up with
./scripts/docker-dev.sh cleanand rebuild with./scripts/docker-dev.sh build. -
Files not syncing between host and container: Files edited on the host should be available immediately in the container since
/appis mounted as a volume.
Next Steps
With your Docker environment configured, head to Phase 1: Syntax and Tool Familiarization to begin your C++ learning journey!