docker命令和後臺參數

Docker官方爲了讓用戶快速瞭解Docker,提供了一個 交互式教程 ,旨在幫助用戶掌握Docker命令行的使用方法。linux

Docker 命令行

下面對Docker的命令清單進行簡單的介紹,詳細內容在後續章節詳細介紹。能夠經過運行 docker ,或者 docker help 命令獲得命令行的幫助信息(咱們仍是以 vmware 上的 coreos 爲操做環境,如無特殊說明後文都採用這個環境):docker

core@localhost ~ $ docker
Usage: docker [OPTIONS] COMMAND [arg...]
 -H=[unix:///var/run/docker.sock]: tcp://host:port to bind/connect to or unix://path/to/socket to use A self-sufficient runtime for linux containers. 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 diff Inspect changes on a container's filesystem events Get real time events from the server 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 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 port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT pause Pause all processes within a container 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 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 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 
  • 其中 info、version是系統環境信息相關的命令
  • events、history、logs 是日誌信息相關的命令
  • login\pull\push\search是DockerHub服務相關的命令
  • 其他都是平常維護相關的命令

命令語法

基本用法:命令+參數ubuntu

core@localhost ~ $ docker info Containers: 7 Images: 123 Storage Driver: btrfs Execution Driver: native-0.2 Kernel Version: 3.16.2+ Operating System: CoreOS 444.0.0 core@localhost ~ $ docker version Client version: 1.2.0 Client API version: 1.14 Go version (client): go1.3.1 Git commit (client): fa7b24f OS/Arch (client): linux/amd64 Server version: 1.2.0 Server API version: 1.14 Go version (server): go1.3.1 Git commit (server): fa7b24f 

單個字符的參數能夠放在一塊兒:centos

core@localhost ~ $ docker run -t -i ubuntu:14.04 /bin/bash #使用分開的參數 root@d512e393fc74:/# exit exit core@localhost ~ $ docker run -ti ubuntu:14.04 /bin/bash #將當個支付的參數放在一塊兒 root@d170dacef325:/# exit exit core@localhost ~ $ docker rm d51 d17 #多個參數放在一行 d51 d17 core@localhost ~ $ 

Docker 後臺進程參數

參數 介紹
--api-enable-cors=false 遠程API調用。
-b, --bridge="" 橋接一個系統上的網橋設備到 Docker 容器裏,當使用 none 能夠停用容器裏的網絡
--bip="" 使用 CIDR 地址來設定網絡橋的 IP。此參數和 -b 不能一塊兒使用。
-D, --debug=false 開啓Debug模式。例如:docker -d -D
-d, --daemon=false 開啓Daemon模式。
--dns=[] 設置容器使用DNS服務器。例如: docker -d --dns 8.8.8.8
-dns-search=[] 設置容器使用指定的DNS搜索域名。如: docker -d --dns-search example.com
--exec-driver="native" 設置容器使用指定的運行時驅動。如:docker -d -e lxc
-G, --group="docker" 在後臺運行模式下,賦予指定的Group到相應的unix socket上。注意,當此參數 --group 賦予空字符串時,將去除組信息
-g, --graph="/var/lib/docker" 設置Docker運行時根目錄
-H, --host=[] 設置後臺模式下指定socket綁定,能夠綁定一個或多個 tcp://host:port, unix:///path/to/socket, fd://* 或 fd://socketfd。如:$ docker -H tcp://0.0.0.0:2375 ps 或者$ export DOCKER_HOST="tcp://0.0.0.0:2375"$ docker ps
-icc=true 設置啓用內聯容器的通訊。
--ip="0.0.0.0" 設置容器綁定IP時使用的默認IP地址
--ip-forward=true 設置啓動容器的 net.ipv4.ip_forward
--iptables=true 設置啓動Docker容器自定義的iptable規則
--mtu=0 設置容器網絡的MTU值,若是沒有這個參數,選用默認 route MTU,若是沒有默認route,就設置成常量值 1500。
-p, --pidfile="/var/run/docker.pid" 設置後臺進程PID文件路徑。
-r, --restart=true 設置重啓以前運行中的容器
-s, --storage-driver="" 設置容器運行時使用指定的存儲驅動,如,指定使用devicemapper,能夠這樣:docker -d -s devicemapper
--selinux-enabled=false 設置啓用selinux支持
--storage-opt=[] 設置存儲驅動的參數

Docker 配置文件位置

Docker 的配置文件能夠設置大部分的後臺進程參數,在各個操做系統中的存放位置不一致api

在 ubuntu 中的位置是:/etc/default/dockerruby

在 centos 中的位置是:/etc/sysconfig/dockerbash

相關文章
相關標籤/搜索