[root@localhost ~]# docker --help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
# 管理命令,就是分类后的命令
Management Commands:
app* Docker App (Docker Inc., v0.9.1-beta3)
builder Manage builds
buildx* Docker Buildx (Docker Inc., v0.7.1-docker)
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
scan* Docker Scan (Docker Inc., v0.12.0)
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
# 命令,早期只有这个
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
镜像管理
镜像是什么
是一个分层存储文件,不是一个单一的文件
一个软件的环境
一个镜像可以创建N个容器
一种标准化的交付
一个不包含Linux内核而又精简的Linux操作系统
常用镜像管理命令
[root@localhost ~]# docker image --help
Usage: docker image COMMAND
Manage images
Commands:
构建镜像
build Build an image from a Dockerfile
查看镜像历史,也就是dockerfile镜像的分层、步骤
history Show the history of an image
导入镜像
import Import the contents from a tarball to create a filesystem image
显示一个或者多个镜像信息
inspect Display detailed information on one or more images
加载tar规定或者标准输入的镜像
load Load an image from a tar archive or STDIN
列出所有镜像
ls List images
删除未使用的镜像,释放空间
prune Remove unused images
拉取镜像到本地
pull Pull an image or a repository from a registry
推送镜像
push Push an image or a repository to a registry
删除镜像
rm Remove one or more images
保存一个或者多个镜像到一个 tar归档文件
save Save one or more images to a tar archive (streamed to STDOUT by default)
创建一个引用源镜像标记目标镜像
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
容器管理
容器命令总览
[root@localhost ~]# docker container --help
Usage: docker container COMMAND
Manage containers
Commands:
attach Attach local standard input, output, and error streams to a running container
将容器的当前状态提交为一个新的镜像
commit Create a new image from a container's changes
拷贝文件/文件夹到容器中
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
在容器中运行某个命令
exec Run a command in a running container
export Export a container's filesystem as a tar archive
查看一个或者多个容器的详细信息
inspect Display detailed information on one or more containers
杀死容器
kill Kill one or more running containers
获取容器的日志
logs Fetch the logs of a container
列出所有容器
ls List containers
pause Pause all processes within one or more containers
列出或者指定容器端口映射
port List port mappings or a specific mapping for the container
移除已经停止的容器
prune Remove all stopped containers
rename Rename a container
重启容器
restart Restart one or more containers
移除容器
rm Remove one or more containers
run Run a command in a new container
启动容器
start Start one or more stopped containers
显示容器资源使用统计
stats Display a live stream of container(s) resource usage statistics
停止容器
stop Stop one or more running containers
显示一个容器运行的进程
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes
Run 'docker container COMMAND --help' for more information on a command.
创建容器
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
常用的创建容器的命令:
# -d, -detach 运行容器到后台
docker run nginx -d
# -i, -interactive 交互式
# -t, -tty 分配一个伪终端
docker exec -it 容器id
# 创建容器时指定环境变量
# -e 用于指定环境变量
docker run -d -e env=prod nginx
# 创建容器时指定端口映射
# 88时宿主机端口,80是容器服务端口
dokcer run -d -p 88:80 nginx
# 创建容器时将容器的所有服务端口都暴露给宿主机的随机端口
docker run -d -P nginx
# 创建容器名称,不指定名称会自动随机生成
docker run --name web -d nginx
# 设置容器的主机名 hostname
docker run -h web -d nginx
# 设置容器的退出重启策略,默认为no,可选值有 always、on-failure
docker run -d --restart always nginx
资源限制相关:
# 这个nginx最多可以使用内存500m,1核心的cpu
docker run -m="500m" --cpus="1" nginx