Docker, Podman
Commands
Section titled “Commands”# Export a container's filesystem as a tar archivedocker export -o ./image.tar <container_name>
# Display Docker system-wide informationdocker info
# Display Docker version informationdocker version
# Show Docker disk usage$ docker system dfTYPE TOTAL ACTIVE SIZE RECLAIMABLEImages 38 6 23.26GB 20.75GB (89%)Containers 8 0 6.613GB 6.613GB (100%)Local Volumes 14 1 3.928GB 2.205GB (56%)Build Cache 128 0 7.887GB 7.887GB
# Clean up unused data (containers, networks, images, volumes)docker system prune
# Clean up unused data including volumesdocker system prune -a --volumes
# Login to Docker registrydocker login [registry]
# Logout from Docker registrydocker logout [registry]# Download an image from a registrydocker pull nginx:1.21.0
# List all imagesdocker images
# List all images (including intermediates)docker images -a
# Save one or more images to a tar archive (streamed to STDOUT by default)docker save -o ./image.tar <image_name>
# Load an image from a tar archivedocker load -i ./image.tar
# Build an image from a Dockerfiledocker build -t <image_name>:<tag> <path_to_dockerfile_directory>
# Build an image with no cachedocker build --no-cache -t <image_name>:<tag> <path_to_dockerfile_directory>
# Tag an imagedocker tag <source_image>:<tag> <target_image>:<tag>
# Remove an imagedocker rmi <image_name>:<tag>
# Remove all unused imagesdocker image prune
# Remove all unused images, not just dangling onesdocker image prune -a
# Show the history of an imagedocker history <image_name>:<tag>
# Push an image to a registrydocker push <image_name>:<tag>
# Search for an image on Docker Hubdocker search <term>Container
Section titled “Container”# Create and start a new containerdocker run -d --name <container_name> <image_name>
# Create and start a container with port mappingdocker run -d -p <host_port>:<container_port> --name <container_name> <image_name>
# Create and start a container with volume mountingdocker run -d -v <host_path>:<container_path> --name <container_name> <image_name>
# Create and start a container with environment variablesdocker run -d -e KEY=VALUE --name <container_name> <image_name>
# List running containersdocker ps
# List all containers (including stopped ones)docker ps -a
# Start a stopped containerdocker start <container_name>
# Stop a running containerdocker stop <container_name>
# Restart a containerdocker restart <container_name>
# Remove a containerdocker rm <container_name>
# Force remove a running containerdocker rm -f <container_name>
# View container logsdocker logs <container_name>
# Follow container logsdocker logs -f <container_name>
# Execute a command in a running containerdocker exec -it <container_name> <command>
# Get a shell inside a running containerdocker exec -it <container_name> bash
# View container detailsdocker inspect <container_name>
# Show container resource usage statisticsdocker stats <container_name>Network
Section titled “Network”# List all networksdocker network ls
# Create a networkdocker network create <network_name>
# Create a network with specific subnet and gatewaydocker network create --subnet=172.18.0.0/16 --gateway=172.18.0.1 <network_name>
# Connect a container to a networkdocker network connect <network_name> <container_name>
# Disconnect a container from a networkdocker network disconnect <network_name> <container_name>
# Remove a networkdocker network rm <network_name>
# Display detailed information on one or more networksdocker network inspect <network_name>
# Remove all unused networksdocker network pruneVolume
Section titled “Volume”# List all volumesdocker volume ls
# Create a volumedocker volume create <volume_name>
# Remove a volumedocker volume rm <volume_name>
# Remove all unused volumesdocker volume prune
# Display detailed information on one or more volumesdocker volume inspect <volume_name>
# Mount a volume when running a containerdocker run -d -v <volume_name>:<container_path> <image_name>
# Mount a host directory as a volumedocker run -d -v <host_path>:<container_path> <image_name>
# Create a read-only volumedocker run -d -v <volume_name>:<container_path>:ro <image_name>Docker Compose
Section titled “Docker Compose”# Start services defined in docker-compose.ymldocker-compose up -d
# Stop services defined in docker-compose.ymldocker-compose down
# View logs for servicesdocker-compose logs
# Follow logs for servicesdocker-compose logs -f
# List containers for servicesdocker-compose ps
# Execute a command in a service containerdocker-compose exec <service_name> <command>
# Build or rebuild servicesdocker-compose build
# Pull service imagesdocker-compose pull
# Scale a service to multiple instancesdocker-compose up -d --scale <service_name>=<number_of_instances>进入container
Section titled “进入container”podman start <container_name>podman attach <container_name>