Docker常用命令操作
1.Docker基本信息查看命令
1.1查看docker帮助命令
[root@host152 ~]# 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* Build with BuildKit (Docker Inc., v0.5.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.8.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.
1.2查看docker详细信息
[root@host152 ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
scan: Docker Scan (Docker Inc., v0.8.0)
Server:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
1.3查看docker版本
[root@host152 ~]# docker --version
Docker version 20.10.7, build f0df350
2.Docker常用操作命令
2.1列出镜镜
[root@host152 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 months ago 13.3kB
2.2查找镜像
[root@host152 ~]# docker search redis
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 9734 [OK]
sameersbn/redis 83 [OK]
grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.2 78
rediscommander/redis-commander Alpine image for redis-commander - Redis man… 63 [OK]
2.3拉取镜像
[root@host152 ~]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
33847f680f63: Pull complete
26a746039521: Pull complete
18d87da94363: Pull complete
5e118a708802: Pull complete
ecf0dbe7c357: Pull complete
46f280ba52da: Pull complete
Digest: sha256:cd0c68c5479f2db4b9e2c5fbfdb7a8acb77625322dd5b474578515422d3ddb59
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
2.4删除镜像
2.4.1删除一个镜像
docker rmi 镜像名称/id
[root@host152 ~]# docker rmi hello-world
2.4.2删除多个镜像
docker rmi 镜像名称1/id1 镜像名称2/id2 ...
[root@host152 ~]#docker rmi hello-world redis
2.4.3删除所有镜像
[root@host152 ~]# docker rmi `docker images ‐q`
2.5创建容器
[root@host152 ~]# docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
后台运行redis容器
[root@host152 ~]# docker run -itd --name redis-docker -p 6379:6379 redis
参数说明
-i: 交互式操作。
-t: 终端。
-d:后台运行
-name:创建容器名称
-p:端口映射,映射容器服务的 6379 端口到宿主机的 6379 端口。外部可以直接通过宿主机ip:6379 访问到 Redis 的服务
2.6查看容器运行信息
2.6.1查看正在运行的容器
[root@host152 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
756fe98d843c redis "docker-entrypoint.s…" 8 minutes ago Up 7 minutes 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis-docker
2.6.2查看历史容器
[root@host152 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
756fe98d843c redis "docker-entrypoint.s…" 16 minutes ago Up 16 minutes 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis-docker
fd5b96fbee6e redis "docker-entrypoint.s…" 18 minutes ago Exited (0) 17 minutes ago redis-test
6923169afc51 hello-world "/hello" About an hour ago Exited (0) About an hour ago elegant_feynman
2.6.3查看最后一次运行的容器
[root@host152 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
756fe98d843c redis "docker-entrypoint.s…" 18 minutes ago Up 18 minutes 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis-docker
2.7登陆容器
命令格式提示
[root@host152 ~]# docker exec --help
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
Options:
-d, --detach Detached mode: run command in the background
--detach-keys string Override the key sequence for detaching a container
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
-i, --interactive Keep STDIN open even if not attached
--privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container
登陆容器,开启终端连接redis
[root@host152 ~]# docker exec -it redis-docker /bin/bash
[root@host152 ~]# docker exec -it redis-docker /bin/bash
root@756fe98d843c:/data# redis-cli
127.0.0.1:6379> set age 10
OK
127.0.0.1:6379> get age
"10"
2.8容器的停启
2.8.1容器的停止
[root@host152 ~]# docker stop redis-docker
redis-docker
[root@host152 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2.8.2容器的启动
[root@host152 ~]# docker start redis-docker
redis-docker
[root@host152 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
756fe98d843c redis "docker-entrypoint.s…" 22 minutes ago Up 3 seconds 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis-docker
2.9查看容器的详细信息
[root@host152 ~]# docker inspect redis-docker
2.10查看容器的日志
[root@host152 ~]# docker logs --help
Usage: docker logs [OPTIONS] CONTAINER
[root@host152 ~]# docker logs redis-docker
1:C 01 Aug 2021 09:22:40.449 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 01 Aug 2021 09:22:40.449 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 01 Aug 2021 09:22:40.449 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 01 Aug 2021 09:22:40.450 * monotonic clock: POSIX clock_gettime
2.11容器间文件的拷贝
[root@host152 myfile]# docker cp --help
Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
Copy files/folders between a container and the local filesystem
Use '-' as the source to read a tar archive from stdin
and extract it to a directory destination in a container.
Use '-' as the destination to stream a tar archive of a
container source to stdout.
Options:
-a, --archive Archive mode (copy all uid/gid information)
-L, --follow-link Always follow symbol link in SRC_PATH
2.11.1启动centos
[root@host152 ~]# docker run -itd --name centos-docker centos /bin/bash
登陆创建的centos容器
[root@host152 ~]# docker exec -it centos-docker /bin/bash
2.11.2复制宿主机文件到运行的docker容器
[root@host152 myfile]# docker cp a.txt centos-docker:/root/dockerfile
登陆容器查看文件是否复制成功
[root@host152 myfile]# docker exec -it centos-docker /bin/bash
[root@0966db9df33d /]# cd /root/dockerfile
[root@0966db9df33d dockerfile]# ll
total 4
-rw-r--r-- 1 root root 24 Aug 1 10:24 a.txt
2.11.3把docker文件复制出来到宿主查
[root@host152 myfile]# docker cp centos-docker:/root/dockerfile/dockerfile.txt /root/myfile/
[root@host152 myfile]# ll
total 8
-rw-r--r-- 1 root root 24 Aug 1 18:24 a.txt
-rw-r--r-- 1 root root 22 Aug 1 18:40 dockerfile.txt
1.12启动挂载目录文件
我们可以在创建容器的时候,将宿主机的目录与容器内的目录进行映射,这样我们就可 以通过修改宿主机某个目录的文件从而去影响容器。
创建容器 添加-v参数 后边为 宿主机目录:容器目录
[root@host152 myfile]# docker run -id --name=centos-load -v /root/myfileload:/root/dockerfile centos
如果有权限问题,是因为CentOS7中的安全模块selinux把权限禁掉了,我们需要添加参数 -- privileged=true 来解决挂载的目录没有权限的问题
[root@host152 myfile]# docker run -id --privileged=true --name=centos-load -v /root/myfileload:/root/dockerfile centos
Docker常用命令操作相关推荐
- Docker常用命令操作——1)、镜像操作;2)、容器操作
Docker常用命令&操作 1).镜像操作 https://hub.docker.com/ 操作 命令 说明 检索 docker search 关键字 eg:docker search red ...
- Docker系列之常用命令操作手册
Docker系列之常用命令操作手册 继上一篇博客Docker系列之原理简单介绍之后,本博客对常用的Docker命令进行实践 文章目录 1.安装虚拟机 2.安装Docker 3.Docker镜像操作 4 ...
- docker常用命令详解
docker常用命令详解 本文只记录docker命令在大部分情境下的使用,如果想了解每一个选项的细节,请参考官方文档,这里只作为自己以后的备忘记录下来. 根据自己的理解,总的来说分为以下几种: Doc ...
- 扫盲 docker 常用命令
欢迎关注方志朋的博客,回复"666"获面试宝典 来源:blog.csdn.net/xuan_lu/article/details/119700854 一.docker常用命令 do ...
- Docker实战第二天(Docker常用命令详解)
Docker常用命令 docker version #查看版本 docker search centos #搜索可用的docker镜像 docker images #查看当前docker所有镜像 do ...
- docker常用命令(总结)
docker常用命令 一.docker镜像操作 1.docker显示本地下载好的镜像: docker images 2.docker下载镜像(例如下载ubuntu12.04): docker pull ...
- Docker常用命令、超实用、讲解清晰明了(rm、stop、start、kill、logs、diff、top、cp、restart ...)
前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 1. 查看docker信息(version.info) # 查看docker版本 $docker v ...
- 【快速安装Docker服务及Docker配置、Docker常用命令。】
一.安装docker服务 命令行输入curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun即可快速安装 如提示curl: ...
- Docker教程(二):docker常用命令
前言 本文根据狂神说视频资料整理.https://www.bilibili.com/video/BV1og4y1q7M4?from=search&seid=164476847288957195 ...
最新文章
- 智能家居正是扎根好时节 蓄积且待春雨
- 自然语言处理中的自注意力机制(Self-Attention Mechanism)
- COMBO--组合拳打穿回调地狱~
- android notification 的总结分析
- 字符串处理 —— 单模式匹配 —— MP 算法与 KMP 算法
- flask-limiter限制单个IP访问的频率和次数
- 设计模式UML类图(摘至《HeadFirst设计模式》)
- Julia: wsl ubuntu下安装、vscode及配置profile错误补正
- 弹性地基梁板法计算原理_基础专题
- 《社会心理学》第一章读书笔记
- 洛谷P2342 叠积木
- Django发送电子邮件
- 全球及中国再生纸包装行业研究及十四五规划分析报告
- 基于SSM(Spring+SpringMVC+MyBatis)的外卖点餐管理系统
- 中国和欧洲两大市场均下了最后通牒,苹果这次恐怕逃不过了
- 数商云商业服务业SaaS管理系统:实现高效业务协作,助力企业完善数字化转型之路
- Luogu5149会议座位
- 立夏游雪上,赏奇花,正当时:天台九遮山
- php生成随机小数保留一位,php生成0~1随机小数的方法(必看)
- python要学多久才可以,python一般需要学多久