1. 镜像命令
1.1 检索镜像
docker search
1.2 获取镜像
docker pull 镜像名
docker pull mysql:8.0.30
1.3 列出镜像
docker images
docker image ls
1.4 删除镜像
docker rmi
docker image rm
删除失败:镜像是否创建了容器=>删除容器
1.5 导出镜像
docker save
1.6 导入镜像
docker load
1.7 Dockerfile定制镜像
//构建镜像
docker build
//运行镜像
docker run
Dockerfile指令
//复制文件
copy
//高级复制
add
//容器启动命令
cmd
//环境变量
ENV
//暴露端口
EXPOSE
待详解
2. 容器命令
2.1 创建容器并启动
docker run -p 外部端口号:内部端口号 --name 别名 \
-v 文件挂载 \
-e 环境变量 \
-d 镜像 \
注释:
-d表示后台运行
例:创建mysql容器
docker run -p 3306:3306 --name mysql3306 \
-v /home/mysql8/log:/var/log/mysql \
-v /home/mysql8/data:/var/lib/mysql \
-v /home/mysql8/conf:/etc/mysql \
-v /home/mysql8/mysql-files:/var/lib/mysql-files \
-e MYSQL_ROOT_PASSWOED=Abc1234% \
-d mysql:8.0.30 \
--character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
2.2 启动容器
docker start
2.3 查看容器列表
//查看在运行的容器列表
dokcer ps
//查看所有容器列表
docker ps -a
2.4 停止容器
docker stop
2.5 重启容器
docker restart
2.6 进入容器
docker exec -it
docker attach
2.7 导出容器
docker export
2.8 导入容器快照
docker import
2.9 删除容器
docker rm
2.10 查看容器的日志
docker logs
2.11 查看容器监控
docker stats
3. docker服务命令
3.1 查看docker版本
docker -v
3.2 查看docker详情信息
docker version
3.3 启动docker
systemctl start docker
3.4 停止docker
systemctl stop docker
3.5 设置docker开机自启
systemctl enable docker
3.6 重启docker服务
service docker restart
3.7 关闭docker
service docker stop
4. docker help文档
See 'docker --help'.
用法: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
选型:
--config string Location of client config files (default "/root/.docker")
-D, --debug 开启debug模式
-H, --host list Daemon socket(s) to connect to
-l, --log-level string 设置日志级别,级别为("debug"|"info"|"warn"|"error"|"fatal") (默认"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 终端打印显示版本信息
管理命令,Management Commands:
builder Manage builds
checkpoint Manage checkpoints
config 管理Docker配置,Manage Docker configs
container 管理容器,Manage containers
engine Manage the docker engine
image 管理镜像,Manage images
manifest Manage Docker image manifests and manifest lists
network 管理网络,Manage networks
node 管理Swarm节点,Manage Swarm nodes
plugin 管理插件,Manage plugins
secret 管理Docker安全,Manage Docker secrets
service 管理服务,Manage services
stack Manage Docker stacks
swarm 管理Swarm集群,Manage Swarm
system 管理Docker系统,Manage Docker
trust Manage trust on Docker images
volume 管理卷,Manage volumes
命令,Commands:
attach 将标准输入和标准输出连接到正在运行的容器
build 使用Dockerfile文件创建镜像
commit 从容器修改项中创建新的镜像
cp 将容器的目录或文件复制到本地文件系统中
create 创建一个新的镜像
deploy Deploy a new stack or update an existing stack
diff 检查容器文件系统的修改
events 实时输出docker服务器中发生的事件
exec 从外部运行容器内部的命令
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.
5. 安装及配置
1. 安装
//删除环境中老版本应用
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
//设置库
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
//安装
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
//运行docker
sudo systemctl start docker
//测试:查看版本
docker -v
//设置docker自启动
systemctl enable docker
//重启
systemctl restart docker
2. 设置阿里云镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://vjur7bjc.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker