docker 命令的简单使用
声明:允许转载,转载请注明链接,谢谢合作!
1.docker search
搜索docker镜像信息
2.docker pull
从镜像库中拉取镜像文件
3.docker push
往镜像库中上传镜像文件
4.docker load --input 镜像文件名
如果是本地的镜像文件,我们需要将其load到镜像库中
5.操作docker镜像
通常我们使用docker run 命令
docker run -i -t ubuntu:14.04 /bin/bash
#运行一个交互式的shell,库中没有镜像的话默认去镜像库中获取
docker run ubuntu env
#查看一个镜像的运行环境
主要显示path信息,home_目录等等
docker
images
#查看所有的镜像信息
docker rmi
#移除镜像
tag 给镜像打标记 Tag an image into a repository 会新增一条镜像记录
e.g.
docker tag d63869855c03 kiwenlau/hadoop-slave:0.1.0
save 将镜像保存成压缩文件 Save an image(s) to a tar archive
e.g.
docker save -o ubuntu_14.04.tar ubuntu:14.04
在docker run 镜像的时候我们还可以加很多附加参数 比如端口映射、主机名、容器名等
docker run -d -p 32769:22 -h hnode1 --name hnode1
具体的参数解释如下:
-a, --attach=[] Attach to stdin, stdout or stderr.
-c, --cpu-shares=0 CPU shares (relative weight) # 设置 cpu 使用权重 --cap-add=[] Add Linux capabilities
--cap-drop=[] Drop Linux capabilities
--cidfile="" Write the container ID to the file # 把容器 id 写入到指定文件
--cpuset="" CPUs in which to allow execution (0-3, 0,1) # cpu 绑定
--detach=false Detached mode: Run container in the background, print new container id # 后台运行容器 --device=[] Add a host device to the container (e.g. --device=/dev/sdc:/dev/xvdc)
--dns=[] Set custom dns servers # 设置 dns --dns-search=[] Set custom dns search domains # 设置 dns 域搜索 -e,
--env=[] Set environment variables # 定义环境变量 --entrypoint="" Overwrite the default entrypoint of the image # ?
--env-file=[] Read in a line delimited file of ENV variables # 从指定文件读取变量值
--expose=[] Expose a port from the container without publishing it to your host # 指定对外提供服务端口
-h, --hostname="" Container host name # 设置容器主机名
-i, --interactive=false Keep stdin open even if not attached # 保持标准输出开启即使没有 attached
--link=[] Add link to another container (name:alias) # 添加链接到另外一个容器
--lxc-conf=[] (lxc exec-driver only) Add custom lxc options --lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
-m, --memory="" Memory limit (format: , where unit = b, k, m or g) # 内存限制
--name="" Assign a name to the container # 设置容器名
--net="bridge" Set the Network mode for the container # 设置容器网络模式 'bridge': creates a new network stack for the container on the docker bridge 'none': no networking for this container 'container:': reuses another container network stack 'host': use the host network stack inside the container.
Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure.
-P, --publish-all=false Publish all exposed ports to the host interfaces # 自动映射容器对外提供服务的端口 -p,
--publish=[] Publish a container's port to the host
# 指定端口映射
format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort
(use 'docker port' to see the actual mapping)
--privileged=false Give extended privileges to this container # 提供更多的权限给容器
--restart="" Restart policy to apply when a container exits (no, on-failure[:max-retry], always) --rm=false Automatically remove the container when it exits (incompatible with -d) # 如果容器退出自动移除和 -d 选项冲突
--security-opt=[] Security Options
--sig-proxy=true Proxify received signals to the process (even in non-tty mode). SIGCHLD is not proxied.
-t, --tty=false Allocate a pseudo-tty # 分配伪终端
-u, --user="" Username or UID # 指定运行容器的用户 uid 或者用户名
6.操作docker容器
docker ps -a #查看所有的容器信息
docker start #启动容器
docker stop #停止容器
docker rm #移除容器
容器只有在停止了之后才能被移除
docker port #可以查看容器映射了哪些端口
更具体的,我们可以用
docker inspect #来查看docker容器的运行参数
另外我们还可以通过命令套用,快速操作容器
停止并删除已经停止的docker容器
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端