Solution:
# Check if Docker is running
docker ps
# Start Docker Desktop (Windows/Mac)
# Or start Docker service (Linux)
sudo systemctl start dockerSolution:
# Find what's using the port
# Windows
netstat -ano | findstr :8080
# Linux/Mac
lsof -i :8080
# Use a different port
docker run -p 8081:80 nginxSolution:
# Add user to docker group
sudo usermod -aG docker $USER
# Log out and log back in, or:
newgrp dockerSolution:
# Clean up unused resources
docker system prune -a
# Remove unused volumes
docker volume prune
# Remove unused images
docker image prune -aSolution:
# Check logs
docker logs container-name
# Run interactively to see errors
docker run -it image-name bash
# Check if CMD/ENTRYPOINT is correct
docker inspect image-nameSolution:
- Check port mapping:
docker psshows port mappings - Verify firewall settings
- Check if container is listening on
0.0.0.0not127.0.0.1 - Verify network configuration
Solution:
- Rebuild image after code changes
- Use volumes for development:
-v $(pwd):/app - Restart container after changes
Problem: You changed ENV variables in Dockerfile but the container still shows old values.
Solution:
# Stop and remove the old container
docker stop container-name
docker rm container-name
# Rebuild the image (use --no-cache to ensure changes are applied)
docker build --no-cache -t image-name:tag .
# Run a new container with the rebuilt image
docker run -d -p 3000:3000 --name container-name image-name:tag
# Verify the environment variable
docker exec container-name printenv NODE_ENVNote: Changes to ENV in Dockerfile only take effect in newly built images. Simply restarting a container won't update environment variables set in the Dockerfile - you must rebuild the image and create a new container.
Alternative: Override at runtime (this doesn't require rebuild):
docker run -d -e NODE_ENV=production -p 3000:3000 --name container-name image-name:tagSolution:
# Check disk usage
docker system df
# Clean up
docker system prune -a --volumes# Inspect container
docker inspect container-name
# View container logs
docker logs container-name
# Execute command in container
docker exec -it container-name sh
# View container processes
docker top container-name
# View network details
docker network inspect network-name
# View volume details
docker volume inspect volume-name- Check Docker documentation: https://docs.docker.com
- Search Stack Overflow
- Check GitHub issues
- Docker community forums
# System information
docker info
docker version
# Resource usage
docker stats
# System events
docker events
# Clean everything
docker system prune -a --volumes