docker 命令的简单使用

来源:互联网 发布:知乎日报 ress kindle 编辑:程序博客网 时间:2024/05/17 22:57
声明:允许转载,转载请注明链接,谢谢合作!
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 tagd63869855c03 kiwenlau/hadoop-slave:0.1.0
save 将镜像保存成压缩文件 Save an image(s) to a tar archive
e.g.     docker save -oubuntu_14.04.tar ubuntu:14.04
在docker run 镜像的时候我们还可以加很多附加参数 比如端口映射、主机名、容器名等
docker run -d -p 32769:22 -h hnode1 --namehnode1 
具体的参数解释如下:
-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 tothe container (e.g.--device=/dev/sdc:/dev/xvdc) 
--dns=[] Set custom dns servers # 设置 dns --dns-search=[] Setcustom 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 withoutpublishing 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, mor 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 onthe docker bridge 'none': no networking for this container'container:': reuses another container network stack 'host': usethe host network stack inside the container. Note: the host mode gives the container fullaccess to local system services such as D-bus and is thereforeconsidered insecure.
-P, --publish-all=false Publish all exposed ports to the hostinterfaces # 自动映射容器对外提供服务的端口 -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 Automaticallyremove the container when it exits (incompatible with -d) #如果容器退出自动移除和 -d 选项冲突 
--security-opt=[] Security Options
--sig-proxy=true Proxify received signals to the process (evenin 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)

原创粉丝点击