Showing posts with label docker stop. Show all posts
Showing posts with label docker stop. Show all posts

2/27/2023

Useful Docker Commands: List, Stop, Remove, Logs, Build, Push, Pull, and Delete Images

 

refer to cmd


.

# List all running containers
docker ps

# List all containers, including stopped ones
docker ps -a

# Stop a running container
docker stop <container-id>

# Remove a stopped container
docker rm <container-id>

# View logs from a container
docker logs <container-id>

# Execute a command in a running container
docker exec <container-id> <command>

# Build an image from a Dockerfile
docker build -t <image-name> <path-to-dockerfile>

# Push an image to a Docker registry
docker push <registry>/<image-name>

# Pull an image from a Docker registry
docker pull <registry>/<image-name>

# Remove all Docker images using prune option
docker image prune -a -f

..


Thank you.

πŸ™‡πŸ»‍♂️

www.marearts.com

10/03/2021

Docker container stop by image name

 Stop docker container by image name:

imagename='mydockerimage'
docker stop $(docker ps | awk '{split($2,image,":"); print $1, image[1]}' | awk -v image=$imagename '$2 == image {print $1}')

Stop docker container by image name and tag:

imagename='mydockerimage:latest'
docker stop $(docker ps | awk -v image=$imagename '$2 == image {print $1}')