banner
云野阁

云野阁

闲云野鹤,八方逍遥

Basic Knowledge of Docker

docker search image # Search for the image to download

docker pull image # Pull the image to local

docker images # View the images pulled to local

docker rmi image_name_or_ID # Delete the image

docker rm container_ID # Delete the stopped container

docker rm -f container_ID # Force delete the container

Delete multiple containers at once

docker rm -f $(docker ps -a -q)

docker ps -a -q | xargs docker rm

Delete dangling images

docker image ls -f dangling=true # Show all dangling images

docker image prune # Delete dangling images

docker ps # View running containers

docker ps -a # List all running and previously run containers

docker ps -l # Show the most recently created container

docker ps -n # Show the most recently created n containers

docker ps -q # Show only container IDs

docker stop container_name_or_ID # Stop the container

docker kill container_name_or_ID # Force stop the container

docker start container_name_or_ID # Start the stopped container

docker restart container_name_or_ID # Restart the container

docker run -it image_name_or_ID # Start the image (-it for interactive start)

docker run -d container_name_or_ID # Run the container in the background

docker run -it -p port_number:port_number container_name_or_ID # Run the container with a specific port number

docker run -it -P container_name_or_ID # Run the container with randomly assigned port numbers

After starting the image, press ctrl+p+q, the container runs in the background

Re-enter the background running container

docker exec -it container_ID # Open a new terminal in the container and start a new process, exit with exit, will not stop the container. (Recommended)

docker attach container_ID # Directly enter the terminal of the container's startup command, will not start a new process, exit with exit, will stop the container.

docker inspect container_ID # Show detailed information inside the container

docker logs container_ID # View container logs

docker top container_ID # View processes inside the container

docker cp container_ID:container_path host_path # Copy files from the container to the host

Import and export of containers

docker export container_ID > filename.tar # Export the container and its contents as a tar package

cat filename.tar | docker import - image_user/image_name:image_version # Create a new filesystem from the tar package and import the image

docker run -it --privileged=true -v /host_directory:/container_directory image_name # Map between host and container to add container volume

docker run -it --privileged=true -v /host_directory:/container_directory:rw image_name # Map between host and container to add container volume, files in the container are readable and writable

docker run -it --privileged=true -v /host_directory:/container_directory:ro image_name # Map between host and container to add container volume, files in the container are read-only

docker run -it --privileged=true --volumes-from parent -name container2_name image_name # Container 2 inherits the volume rules from container 1

image-20240323215245387

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.