设为首页 收藏本站
查看: 896|回复: 0

[经验分享] docker——常有命令及参数

[复制链接]

尚未签到

发表于 2017-12-7 07:35:16 | 显示全部楼层 |阅读模式
  写在前面:
  继续docker的学习,昨天晚上安装在VirtualBox的Centos6.5上成功装好了docker 1.7.0,今天对docker的常用命令进行学习。
  命令格式:
  docker的命令格式如下:



docker [OPTIONS] COMMAND [arg...]
  OPTION(可选参数):



Options:
--api-cors-header=                   Set CORS headers in the remote API
-b, --bridge=                        Attach containers to a network bridge
--bip=                               Specify network bridge IP
-D, --debug=false                    Enable debug mode
-d, --daemon=false                   Enable daemon mode
--default-gateway=                   Container default gateway IPv4 address
--default-gateway-v6=                Container default gateway IPv6 address
--default-ulimit=[]                  Set default ulimits for containers
--dns=[]                             DNS server to use
--dns-search=[]                      DNS search domains to use
-e, --exec-driver=native             Exec driver to use
--exec-opt=[]                        Set exec driver options
--exec-root=/var/run/docker          Root of the Docker execdriver
--fixed-cidr=                        IPv4 subnet for fixed IPs
--fixed-cidr-v6=                     IPv6 subnet for fixed IPs
-G, --group=docker                   Group for the unix socket
-g, --graph=/var/lib/docker          Root of the Docker runtime
-H, --host=[]                        Daemon socket(s) to connect to
-h, --help=false                     Print usage
--icc=true                           Enable inter-container communication
--insecure-registry=[]               Enable insecure registry communication
--ip=0.0.0.0                         Default IP when binding container ports
--ip-forward=true                    Enable net.ipv4.ip_forward
--ip-masq=true                       Enable IP masquerading
--iptables=true                      Enable addition of iptables rules
--ipv6=false                         Enable IPv6 networking
-l, --log-level=info                 Set the logging level
--label=[]                           Set key=value labels to the daemon
--log-driver=json-file               Default driver for container logs
--log-opt=map[]                      Set log driver options
--mtu=0                              Set the containers network MTU
-p, --pidfile=/var/run/docker.pid    Path to use for daemon PID file
--registry-mirror=[]                 Preferred Docker registry mirror
-s, --storage-driver=                Storage driver to use
--selinux-enabled=false              Enable selinux support
--storage-opt=[]                     Set storage driver options
--tls=false                          Use TLS; implied by --tlsverify
--tlscacert=~/.docker/ca.pem         Trust certs signed only by this CA
--tlscert=~/.docker/cert.pem         Path to TLS certificate file
--tlskey=~/.docker/key.pem           Path to TLS key file
--tlsverify=false                    Use TLS and verify the remote
--userland-proxy=true                Use userland proxy for loopback traffic
-v, --version=false                  Print version information and quit
  COMMAND(命令)



Commands:
attach    Attach 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 from a container's filesystem to the host path
    create    Create a new container
diff      Inspect changes on a container's filesystem
events    Get real time events from the server
exec      Run a command in a running container
export    Stream the contents of a container as a tar archive
history   Show the history of an image
images    List images
import    Create a new filesystem image from the contents of a tarball
info      Display system-wide information
inspect   Return low-level information on a container or image
kill      Kill a running container
load      Load an image from a tar archive
login     Register or log in to a Docker registry server
logout    Log out from a Docker registry server
logs      Fetch the logs of a container
pause     Pause all processes within a container
port      Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
ps        List containers
pull      Pull an image or a repository from a Docker registry server
push      Push an image or a repository to a Docker registry server
rename    Rename an existing container
restart   Restart a running container
rm        Remove one or more containers
rmi       Remove one or more images
run       Run a command in a new container
save      Save an image to a tar archive
search    Search for an image on the Docker Hub
start     Start a stopped container
stats     Display a stream of a containers' resource usage statistics
    stop      Stop a running container
tag       Tag an image into a repository
top       Lookup the running processes of a container
unpause   Unpause a paused container
version   Show the Docker version information
wait      Block until a container stops, then print its exit code
  arg... (命令参数)
  可以通过 docker COMMAND --help 查看命令支持的参数



[iyunv@niloay ~]# docker ps --help
Usage: docker ps [OPTIONS]
List containers
-a, --all=false       Show all containers (default shows just running)
--before=             Show only container created before Id or Name
-f, --filter=[]       Filter output based on conditions provided
--help=false          Print usage
-l, --latest=false    Show the latest created container, include non-running
-n=-1                 Show n last created containers, include non-running
--no-trunc=false      Don't truncate output
-q, --quiet=false     Only display numeric IDs
-s, --size=false      Display total file sizes
--since=              Show created since Id or Name, include non-running
  常用命令:
  --- 镜像 ---
  1、docker镜像检索



# docker search 镜像名
docker search centos
  2、docker镜像下载 (等待时间不是一般久)



# docker pull 镜像名
docker pull centos
  3、docker镜像列表



docker images
  4、docker镜像删除



# docker rmi  image-id (镜像id)
docker rmi 34336sdf12
  5、删除所有镜像



docker rmi  $(docker images -q)
  --- 容器 ---
  1、创建并运行容器



# docker run 镜像命名
docker run centos
# 指定容器名
docker run --name webcentos  centos
# 以守护进程的方式运行容器
docker run --name webcentos -d centos
  2、容器列表



docker ps
  3、容器状态



docker ps -a
  4、停止容器



# docker  stop 容器名称/容器Id
docker stop webcentos
  5、启动容器



# docker start 容器名称/容器Id
docker start webcentos
  6、删除容器



# docker rm 容器id
docker rm 235483s15c
  7、删除所有容器



docker rm $(docker ps -a -q)
  8、容器日志



# docker logs 容器名称/容器id
docker logs webcentos
  9、登陆容器



# docker exec -it 容器名称/容器id  /bin/bash
docker exec -it webcentos /bin/bash
    其中, -t 选项让Docker分配一个伪终端( pseudo-tty)并绑定到容器的标准输入上, -i 则让容器的标准输入保持打开。
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-421547-1-1.html 上篇帖子: Docker Mysql主从同步配置搭建Demo 下篇帖子: springboot构建rest服务,打包docker镜像
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表