Docker Key Commands

Photo by Ian Taylor on Unsplash

Docker Key Commands

In a Docker context, Docker commands offer strong capabilities for controlling images and containers. Commands like "docker run" and "docker create" make it simple for users to build, run, and manage containers. "Docker images" and "docker ps" assist in listing and viewing available images and containers. Commands like "docker network" and "docker volume" make managing networks and volumes easier. Complex configurations involving numerous containers can be orchestrated with the help of Docker Compose and Docker Swarm commands. Control over system-wide data and image creation is also possible with the use of system and Dockerfile commands. To deal with Docker containers and images properly, you must comprehend these commands.

Here are Docker key commands :

Image Commands:

  1. docker images: List all available images.

  2. docker pull <image>: Download an image from a registry.

  3. docker push <image>: Upload an image to a registry.

  4. docker build -t <image-name> <path>: Build an image from a Dockerfile.

Container Commands:

  1. docker ps: List running containers.

  2. docker ps -a: List all containers.

  3. docker create <image>: Create a new container.

  4. docker start <container>: Start a stopped container.

  5. docker stop <container>: Stop a running container.

  6. docker restart <container>: Restart a container.

  7. docker rm <container>: Remove a container.

  8. docker rmi <image>: Remove an image.

  9. docker exec -it <container> <command>: Run a command in a running container.

  10. docker logs <container>: View container logs.

  11. docker stats <container>: Display container resource usage.

  12. docker top <container>: Display running processes in a container.

  13. docker rename <container> <new-name>: Rename a container.

  14. docker wait <container>: Block until a container stops.

Container Management Commands:

  1. docker-compose up: Create and start containers defined in a Compose file.

  2. docker-compose down: Stop and remove containers defined in a Compose file.

  3. docker-compose logs: View logs from containers started with Compose.

Networking Commands:

  1. docker network ls: List networks.

  2. docker network create <network>: Create a new network.

  3. docker network connect <network> <container>: Connect a container to a network.

  4. docker network disconnect <network> <container>: Disconnect a container from a network.

Volume Commands:

  1. docker volume ls: List volumes.

  2. docker volume create <volume>: Create a new volume.

  3. docker volume rm <volume>: Remove a volume.

  4. docker run -v <host-path>:<container-path> <image>: Attach a volume to a container.

Registry Commands:

  1. docker login: Log in to a Docker registry.

  2. docker logout: Log out of a Docker registry.

System Commands:

  1. docker info: Display system-wide information.

  2. docker version: Display Docker version information.

  3. docker system df: Show disk usage.

  4. docker system prune: Remove all unused objects.

  5. docker system events: Get real-time events from the server.

Docker Swarm Commands:

  1. docker swarm init: Initialize a swarm.

  2. docker node ls: List nodes in a swarm.

  3. docker service create: Create a new service in a swarm.

  4. docker service ls: List services in a swarm.

  5. docker stack deploy: Deploy a stack (Compose file) to a swarm.

Dockerfile Commands:

  1. FROM <image>: Specify the base image.

  2. RUN <command>: Execute a command during image build.

  3. CMD [“executable”,”param1",”param2"]: Define the default container command.

  4. WORKDIR /path: Set the working directory for subsequent commands.

  5. COPY <src> <dest>: Copy files or directories into the image.

  6. ADD <src> <dest>: Copy files, including remote URLs.

  7. EXPOSE <port>: Expose a port for networking.

  8. ENV <key> <value>: Set environment variables.

  9. ARG <var-name>: Define a build-time variable.

  10. VOLUME /path: Create a mount point for a volume.

  11. USER <username>: Set the user for subsequent commands.

  12. HEALTHCHECK CMD [“executable”]: Set a health check instruction.

  13. ONBUILD <instruction>: Add an instruction to be executed later.

  14. LABEL <key>=<value>: Add metadata to an image.

  15. SHELL [“executable”, “param1”, “param2”]: Override the shell used for executing commands.

Docker Compose Commands:

  1. docker-compose up: Create and start services defined in a Compose file.

  2. docker-compose down: Stop and remove services defined in a Compose file.

  3. docker-compose logs: View logs from services started with Compose.

Docker Hub Commands:

  1. docker search <image>: Search for images on Docker Hub.