- Detaljer
- Treff: 0
Here is a list of commonly used Docker commands, categorized by purpose:
1. Docker Basics
- Check Docker version:
docker --version
- Show system-wide information about Docker:
docker info
2. Container Management
-
List running containers:
docker ps
-
List all containers (including stopped ones):
docker ps -a
-
Run a new container:
docker run <image_name>
Common options:
-it
: Run interactively with a terminal.--name <container_name>
: Assign a name to the container.-d
: Run in detached mode (background).-p <host_port>:<container_port>
: Map ports.
Example:
docker run -it --name my-container -p 8080:80 nginx
-
Start a stopped container:
docker start <container_name_or_id>
-
Stop a running container:
docker stop <container_name_or_id>
-
Restart a container:
docker restart <container_name_or_id>
-
Remove a container:
docker rm <container_name_or_id>
-
Remove all stopped containers:
docker container prune
3. Image Management
- List Docker images:
docker images
- Pull an image from Docker Hub:
docker pull <image_name>
- Build an image from a Dockerfile:
docker build -t <image_name> <path_to_dockerfile_directory>
- Tag an image:
docker tag <image_name>:<tag> <new_image_name>:<new_tag>
- Remove an image:
docker rmi <image_name_or_id>
- Remove unused images:
docker image prune
4. Network Management
- List Docker networks:
docker network ls
- Inspect a network:
docker network inspect <network_name>
- Create a new network:
docker network create <network_name>
- Connect a container to a network:
docker network connect <network_name> <container_name_or_id>
- Disconnect a container from a network:
docker network disconnect <network_name> <container_name_or_id>
5. Volumes
- List volumes:
docker volume ls
- Create a volume:
docker volume create <volume_name>
- Inspect a volume:
docker volume inspect <volume_name>
- Remove a volume:
docker volume rm <volume_name>
- Remove unused volumes:
docker volume prune
6. Logs and Monitoring
- View logs of a container:
docker logs <container_name_or_id>
- Stream logs in real time:
docker logs -f <container_name_or_id>
- View resource usage of containers:
docker stats
7. Docker Compose
- Start services defined in
docker-compose.yml
:docker-compose up
-d
: Run in detached mode.
- Stop services:
docker-compose down
- View running services:
docker-compose ps
Would you like to explore a specific command in more detail?
- Detaljer
- Treff: 0
- Detaljer
- Treff: 0
- Detaljer
- Treff: 0
Business
Sample text. Click to select the text box. Click again or double click to start editing the text.