Docker Command

Basic Docker Commands:

● docker --version: Display Docker version.

● docker info: Display system-wide information.

● docker run image: Run a Docker container from an image.

● docker ps: List running Docker containers.

● docker ps -a: List all Docker containers.

● docker stop container_id: Stop a running container.

● docker rm container_id: Remove a Docker container.

● docker images: List Docker images.

● docker rmi image_id: Remove a Docker image.

● docker push image: Push an image to a Docker registry.

● docker exec -it container_id command: Execute a command in a running container.

● docker logs container_id: Fetch the logs of a container.

● docker start: Starts one or more stopped containers.

● docker stop: Stops one or more running containers.

● docker build: Builds an image from a Dockerfile.

● docker pull: Pulls an image or a repository from a registry.

● docker push: Pushes an image or a repository to a registry.

● docker export: Exports a container’s filesystem as a tar archive.

● docker exec: Runs a command in a run-time container.

● docker search: Searches the Docker Hub for images.

● docker attach: Attaches to a running container.

● docker commit: Creates a new image from a container’s changes.

● docker pull image: Pull an image from a Docker registry (Docker Hub by default).

Intermediate Docker Commands:

● docker run -d image: Run a Docker container in detached mode.

● docker run -p host_port:container_port image: Map a port from the host to a container.

● docker run -v host_volume:container_volume image: Mount a volume from the host to a container.

● docker run -e VAR=VALUE image: Set environment variables in a container.

● docker inspect container_id/image_id: Return low-level information on Docker objects.

● docker build -t tag .: Build a Docker image with a tag from a Dockerfile in the current directory.

● docker tag image new_tag: Tag an image with a new tag.

Docker Compose Commands:

● docker-compose up: Create and start containers.

● docker-compose down: Stop and remove containers, networks, images, and volumes.

● docker-compose build: Build or rebuild services.

● docker-compose logs: View output from containers.

● docker-compose restart: Restart services.

● docker-compose pause: Pause services.

● docker-compose unpause: Unpause services.

● docker-compose start: Starts existing containers for a service.

● docker-compose stop: Stops running containers without removing them.

● docker-compose config: Validates and views the compose file.

Docker Networking:

● docker network ls: List networks.

● docker network create network: Create a network.

● docker network rm network: Remove a network.

● docker network inspect network: Display detailed information on one or more networks.

Docker Volumes:

● docker volume ls: List volumes.

● docker volume create volume: Create a volume.

● docker volume rm volume: Remove a volume.

● docker volume inspect volume: Display detailed information on one or more volumes.

Docker Object Commands:

● docker image: Manages images.

● docker container: Manages containers.

● docker network: Manages networks.

● docker volume: Manages volumes.

● docker secret: Manages Docker secrets.

● docker plugin: Manages plugins.

Docker Advanced Commands:

● docker history image: Show the history of an image.

● docker save image > file: Save an image to a tar archive.

● docker load < file: Load an image from a tar archive.

● docker commit container image: Create a new image from a container’s changes.

Docker Security:

● docker secret create secret file: Create a secret from a file.

● docker secret ls: List secrets.

● docker secret rm secret: Remove a secret.