Docker commands:
Image Management:
docker pull <image_name>: Pulls an image from a Docker registry.
docker build -t <image_name> <path_to_dockerfile>: Builds a Docker image from a Dockerfile.
docker images: Lists all locally available Docker images.
docker rmi <image_name>: Removes a Docker image.
Container Lifecycle:
Create and run a container: docker run <image_name>
List running containers: docker ps
List all containers: docker ps -a
Start a container: docker start <container_id/container_name>
Stop a container: docker stop <container_id/container_name>
Restart a container: docker restart <container_id/container_name>
Remove a container: docker rm <container_id/container_name>
Container Inspection:
Inspect a container: docker inspect <container_id/container_name>
Display container logs: docker logs <container_id/container_name>
Display running processes: docker top <container_id/container_name>
Container Interactions:
Execute command in container: docker exec -it <container_id/container_name>
Open shell in container: docker exec -it <container_id/container_name> /bin/bash Copy files between host and container: docker cp <local_path> <container_id/container_name>:<container_path>
Container Networking:
List networks: docker network ls
Create network: docker network create <network_name>
Connect container to network: docker network connect <network_name> <container_id/container_name>
Disconnect container from network: docker network disconnect <network_name> <container_id/container_name>
Docker Compose: Start containers defined in docker-compose.yml: docker-compose up
Stop and remove containers: docker-compose down
Cleanup:
Remove unused resources: docker system prune
Remove all unused resources: docker system prune -a
Docker Volume Management:
docker volume create <volume_name>: Creates a named volume.
docker volume ls: Lists all volumes.
docker volume inspect <volume_name>: Displays detailed information about a volume.
docker volume prune: Removes all unused volumes.
Docker Container Lifecycle (Advanced):
docker run -d <image_name>: Runs a container in detached mode (in the background).
docker run --rm <image_name>: Removes the container after it exits.
docker pause <container_id/container_name>: Pauses a running container.
docker unpause <container_id/container_name>: Unpauses a paused container.
docker wait <container_id/container_name>: Blocks until a container stops, then prints its exit code.
docker kill <container_id/container_name>: Sends a signal to a running container to stop it.
Docker Image Tagging and Pushing:
docker tag <image_id> <new_image_name:tag>: Tags an existing image.
docker push <image_name:tag>: Pushes an image to a Docker registry.
Docker Build with Build Context:
docker build -t <image_name> <path_to_build_context>: Builds an image using a build context at a specified path.
Docker Network Inspection:
docker network inspect <network_name>: Displays detailed information about a network.
Docker System Information:
docker info: Displays system-wide information about Docker.
docker version: Displays Docker version information.
docker system df: Shows information about Docker disk usage.
Docker Compose Management:
docker-compose up -d: Starts containers in detached mode.
docker-compose logs <service_name>: Displays logs for a specific service.
docker-compose exec <service_name> : Executes a command in a running service container.
docker-compose build: Builds services defined in a docker-compose.yml file.