# Images
代码语言:javascript复制# build image from a Dockerfile
docker build -t <image-name> .
# build image from a Dockerfile without cache
docker build --no-cache -t <image-name> .
# list local images
docker images
# delete local image
docker rmi <image-name>
# delete all unused images
docker image prune
# Docker Hub
代码语言:javascript复制# login to Docker Hub
docker login -u <username>
# publish image to Docker Hub
docker push <username>/<image-name>
# search image on Docker Hub
docker search <image-name>
# pull image from Docker Hub
docker pull <image-name>
# Containers
代码语言:javascript复制# run a container with a name
docker run --name <container-name> <image-name>
# run a container with a port mapping
docker run -p <host-port>:<container-port> <image-name>
# run a container in the background
docker run -d <image-name>
# start or stop an existing container
docker start|stop <container-name>|<container-id>
# remove a stopped container
docker rm <container-name>|<container-id>
# open a shell inside a running container
docker exec -it <container-name>|<container-id> sh
# fetch and follow the logs of a container
docker logs -f <container-name>|<container-id>
# to inspect a running container
docker inspect <container-name>|<container-id>
# list running containers
docker ps
# list all containers
docker ps -a
# view resource usage statistics
docker container stats
# Docker Compose
# Basic example
docker-compose.yml
version: "2"
services:
web:
build: .
context: ./Path
dockerfile: Dockerfile
ports:
- "5000:5000"
volumes:
- .:/code
redis:
image: redis
# Commands
代码语言:javascript复制docker-compose start
docker-compose stop
docker-compose pause
docker-compose unpause
docker-compose up
docker-compose down
docker-compose ps