This guide covers advanced Docker configuration topics including user ID mapping, build arguments, network modes, and performance optimization.
The environment automatically maps your user ID and group ID into containers to avoid permission issues.
When building containers, your UID and GID are passed as build arguments:
docker-compose build --build-arg UID=$(id -u) --build-arg GID=$(id -g)This ensures:
- Files created in containers have your ownership
- You can edit files created by containers
- No
sudoneeded for file operations
Check your IDs:
id -u # Your UID
id -g # Your GIDCheck container user:
dev console
idShould match your host user.
To override the automatic detection, set in .env:
UID=1000
GID=1000Build arguments customize container builds without modifying Dockerfiles.
The environment supports:
UID- User IDGID- Group IDPHP_VERSION- PHP version for buildsCOMPOSER_MEMORY_LIMIT- Composer memory limit
In docker-custom.yml:
version: '2'
services:
php:
build:
context: custom/php
args:
PHP_VERSION: 8.3
CUSTOM_ARG: valueIn your custom Dockerfile:
ARG PHP_VERSION=8.2
FROM php:${PHP_VERSION}-fpm
ARG CUSTOM_ARG
RUN echo "Custom arg: ${CUSTOM_ARG}"Most services use the default bridge network, allowing container-to-container communication.
Services can reference each other by name:
// From PHP container
$redis = new Redis();
$redis->connect('redis', 6379);
$db = new PDO('mysql:host=db;dbname=mydb', 'user', 'pass');Some services use host network mode for direct access to host networking:
- ngrok - For tunneling
- expose - For sharing
In docker-custom.yml:
services:
myservice:
network_mode: hostCreate isolated networks for specific services:
version: '2'
services:
myapp:
networks:
- frontend
- backend
mydb:
networks:
- backend
networks:
frontend:
backend:
internal: true # No external accessOn Linux, volumes have native performance. Use bind mounts freely:
volumes:
- ./workspace:/data/workspaceOn macOS, use Docker volumes instead of bind mounts for better performance:
dev volume workspace workspaceOr use delegated/cached modes:
volumes:
- ./workspace:/data/workspace:delegatedSimilar to macOS, Docker volumes offer better performance than bind mounts.
Limit container resources to prevent one service from consuming all resources.
In docker-custom.yml:
services:
db:
mem_limit: 2g
memswap_limit: 2g
elasticsearch:
mem_limit: 1g
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"services:
php:
cpus: '2.0' # Use up to 2 CPU cores
cpu_shares: 1024 # Relative weightControl what happens when containers exit:
services:
critical-service:
restart: always
optional-service:
restart: unless-stopped
dev-tool:
restart: "no"The environment uses Compose file version 2 for compatibility:
version: '2'Version 2 provides:
- Wide compatibility
- Named volumes
- Network support
- Stable feature set
Enable Docker BuildKit for faster, more efficient builds:
export DOCKER_BUILDKIT=1
dev rebuildOr permanently in ~/.bashrc or ~/.zshrc:
export DOCKER_BUILDKIT=1Benefits:
- Parallel build stages
- Better layer caching
- Reduced build time
- Lower disk usage
Add health checks to services:
services:
db:
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30sCheck health status:
dev psControl container log output:
services:
php:
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"This prevents logs from consuming excessive disk space.
Make containers more secure with read-only filesystems:
services:
web:
read_only: true
tmpfs:
- /tmp
- /var/runRemove unnecessary Linux capabilities:
services:
app:
cap_drop:
- ALL
cap_add:
- NET_BIND_SERVICEFor additional security, enable Docker user namespace remapping. See Docker documentation.
Rebuild with correct UID/GID:
dev rebuildOr fix permissions on host:
sudo chown -R $USER:$USER workspace/Inspect networks:
docker network ls
docker network inspect dockerdev_defaultClear build cache:
docker builder prune
dev rebuild --no-cacheCheck resource usage:
dev top
docker system dfClean up:
docker system prune -a
docker volume prune- custom-compose-files.md - Custom configurations
- docker-volumes.md - Volume management
- performance-tuning.md - Optimization techniques