dockerベースの使い方とコマンド
25077 ワード
1.ミラーの検索
#docker search ubuntu
2.ミラーの取得
#docker pull ubuntu
3.現在のミラーリストを表示する
#docker p_w_picpaths
4.コンテナの実行
#docker run –i –t ubuntu:14.04/bin/bash
docker runコンテナを実行する
-tは偽ttyを割り当てる
-iインタラクティブモード
ubuntu:14.04 ubuntuベースミラー14.04を使用
/bin/bash-コマンドbash shellの実行
docker tag [p_w_picpath]: [tag]
例:#docker tag ubuntu:15.10 runoob/ubuntu:v 3
docker help
docker command
docker option
4.2 docker search
例:
4.3 docker info
4.4 docker pull && docker push
例:
4.5 docker p_w_picpaths
現在のシステムミラーを一覧表示
例:
4.6 docker rmi
1つ以上のミラーを削除
4.7 docker run
例:
cpu優先度について:
By default all groups have 1024 shares. A group with 100 shares will get a ~10% portion of the CPU time -archlinux cgroups
4.8 docker start|stop|kill... ...
dockerstart|stop|kill|restart|pause|unpause|rm|commit|inspect|logs docker start CONTAINER [CONTAINER...] #1つ以上の停止容器 を運転する
docker stop CONTAINER [CONTAINER...] #1つまたは複数の実行コンテナを停止-tオプションでタイムアウト時間 を指定できます.
docker kill [OPTIONS] CONTAINER [CONTAINER...] #デフォルトkill送信SIGKILL信号-sは、送信kill信号タイプ を指定することができる.
docker restart [OPTIONS] CONTAINER [CONTAINER...] #1つ以上の実行を再開するコンテナ-tオプションタイムアウト時間 を指定します.
docker pause CONTAINER #容器を一時停止し、便利commit docker unpause CONTAINER #一時停止を継続する容器 docker rm [OPTIONS] CONTAINER [CONTAINER...] #1つまたは複数のコンテナを除去 -f, --force=false Force removal of running container -l, --link=false Remove the specified link and not the underlying container -v, --volumes=false Remove the volumes associated with the container
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] #デフォルトcommitは一時停止状態 です.#指定コンテナをミラーとしてコミット -a, --author=""Author (e.g., "John Hannibal Smith [email protected]") -m, --message=""Commit message -p, --pause=true Pause container during commit
docker inspect CONTAINER|IMAGE [CONTAINER|IMAGE...] #コンテナまたはミラーの詳細を表示する docker logs CONTAINER #tail-f に類似#指定コンテナログ情報 を出力する. -f, --follow=false Follow log output -t, --timestamps=false Show timestamps --tail="all"Output the specified number of lines at the end of logs (defaults to all logs)
転載先:https://blog.51cto.com/lishenggui/1926553
#docker search ubuntu
2.ミラーの取得
#docker pull ubuntu
3.現在のミラーリストを表示する
#docker p_w_picpaths
4.コンテナの実行
#docker run –i –t ubuntu:14.04/bin/bash
docker runコンテナを実行する
-tは偽ttyを割り当てる
-iインタラクティブモード
ubuntu:14.04 ubuntuベースミラー14.04を使用
/bin/bash-コマンドbash shellの実行
docker tag [p_w_picpath]: [tag]
例:#docker tag ubuntu:15.10 runoob/ubuntu:v 3
docker help
docker command
$ sudo docker # docker
Commands:
attach Attach to a running container # shell attach
build Build an p_w_picpath from a Dockerfile # Dockerfile
commit Create a new p_w_picpath from a container's changes #
cp Copy files/folders from the containers filesystem to the host path
#
create Create a new container # , run,
diff Inspect changes on a container's filesystem # docker
events Get real time events from the server # docker
exec Run a command in an existing container #
export Stream the contents of a container as a tar archive
# tar [ import ]
history Show the history of an p_w_picpath #
p_w_picpaths List p_w_picpaths #
import Create a new filesystem p_w_picpath from the contents of a tarball
# tar [ export]
info Display system-wide information #
inspect Return low-level information on a container #
kill Kill a running container # kill docker
load Load an p_w_picpath from a tar archive # tar [ save]
login Register or Login to the docker registry server
# docker
logout Log out from a Docker registry server # Docker registry
logs Fetch the logs of a container #
port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
#
pause Pause all processes within a container #
ps List containers #
pull Pull an p_w_picpath or a repository from the docker registry server
# docker
push Push an p_w_picpath or a repository to the docker registry server
# docker
restart Restart a running container #
rm Remove one or more containers #
rmi Remove one or more p_w_picpaths
# [ , -f ]
run Run a command in a new container
#
save Save an p_w_picpath to a tar archive # tar [ load]
search Search for an p_w_picpath on the Docker Hub # docker hub
start Start a stopped containers #
stop Stop a running containers #
tag Tag an p_w_picpath into a repository #
top Lookup the running processes of a container #
unpause Unpause a paused container #
version Show the docker version information # docker
wait Block until a container stops, then print its exit code
#
Run 'docker COMMAND --help' for more information on a command.
docker option
Usage of docker:
--api-enable-cors=false Enable CORS headers in the remote API # API CORS
-b, --bridge="" Attach containers to a pre-existing network bridge #
use 'none' to disable container networking
--bip="" Use this CIDR notation address for the network bridge's IP, not compatible with -b
# -b ,
-d, --daemon=false Enable daemon mode # daemon
-D, --debug=false Enable debug mode # debug
--dns=[] Force docker to use specific DNS servers # docker dns
--dns-search=[] Force Docker to use specific DNS search domains # docker dns
-e, --exec-driver="native" Force the docker runtime to use a specific exec driver # docker
--fixed-cidr="" IPv4 subnet for fixed IPs (ex: 10.20.0.0/16)
this subnet must be nested in the bridge subnet (which is defined by -b or --bip)
-G, --group="docker" Group to assign the unix socket specified by -H when running in daemon mode
use '' (the empty string) to disable setting of a group
-g, --graph="/var/lib/docker" Path to use as the root of the docker runtime #
-H, --host=[] The socket(s) to bind to in daemon mode # daemon docker [tcp or socket]
specified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.
--icc=true Enable inter-container communication #
--insecure-registry=[] Enable insecure communication with specified registries (no certificate verification for HTTPS and enable HTTP fallback) (e.g., localhost:5000 or 10.20.0.0/16)
--ip="0.0.0.0" Default IP address to use when binding container ports # , ip
--ip-forward=true Enable net.ipv4.ip_forward #
--ip-masq=true Enable IP masquerading for bridge's IP range
--iptables=true Enable Docker's addition of iptables rules # iptables
--mtu=0 Set the containers network MTU # mtu
if no value is provided: default to the default route MTU or 1500 if no default route is available
-p, --pidfile="/var/run/docker.pid" Path to use for daemon PID file # pid
--registry-mirror=[] Specify a preferred Docker registry mirror
-s, --storage-driver="" Force the docker runtime to use a specific storage driver # docker
--selinux-enabled=false Enable selinux support # selinux
--storage-opt=[] Set storage driver options #
--tls=false Use TLS; implied by tls-verify flags # tls
--tlscacert="/root/.docker/ca.pem" Trust only remotes providing a certificate signed by the CA given here
--tlscert="/root/.docker/cert.pem" Path to TLS certificate file # tls
--tlskey="/root/.docker/key.pem" Path to TLS key file # tls key
--tlsverify=false Use TLS and verify the remote (daemon: verify client, client: verify daemon) # tls
-v, --version=false Print version information and quit # docker
4.2 docker search
$ sudo docker search --help
Usage: docker search TERM
Search the Docker Hub for p_w_picpaths # Docker Hub --automated=false Only show automated builds
--no-trunc=false Don't truncate output
-s, --stars=0 Only displays with at least xxx stars
例:
$ sudo docker search -s 100 ubuntu # star 100 , start 100, s ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Official Ubuntu base p_w_picpath 425 [OK]
4.3 docker info
$ sudo docker info
Containers: 1 # Images: 22 # Storage Driver: devicemapper # Pool Name: docker-8:17-3221225728-pool
Pool Blocksize: 65.54 kB
Data file: /data/docker/devicemapper/devicemapper/data
Metadata file: /data/docker/devicemapper/devicemapper/metadata
Data Space Used: 1.83 GB
Data Space Total: 107.4 GB
Metadata Space Used: 2.191 MB
Metadata Space Total: 2.147 GB
Library Version: 1.02.84-RHEL7 (2014-03-26) Execution Driver: native-0.2 # Kernel Version: 3.10.0-123.el7.x86_64
Operating System: CentOS Linux 7 (Core)
4.4 docker pull && docker push
$ sudo docker pull --help # pull Usage: docker pull [OPTIONS] NAME[:TAG] Pull an p_w_picpath or a repository from the registry
-a, --all-tags=false Download all tagged p_w_picpaths in the repository $ sudo docker push # push Usage: docker push NAME[:TAG] Push an p_w_picpath or a repository to the registry
例:
$ sudo docker pull ubuntu # ubuntu docker , ubuntu $ sudo docker pull ubuntu:14.04 # ubuntu
$ sudo docker push 192.168.0.100:5000/ubuntu # [ docker , ] $ sudo docker push 192.168.0.100:5000/ubuntu:14.04 #
4.5 docker p_w_picpaths
現在のシステムミラーを一覧表示
$ sudo docker p_w_picpaths --help
Usage: docker p_w_picpaths [OPTIONS] [NAME] List p_w_picpaths
-a, --all=false Show all p_w_picpaths (by default filter out the intermediate p_w_picpath layers) # -a , , docker p_w_picpaths , -f, --filter=[] Provide filter values (i.e. 'dangling=true') --no-trunc=false Don't truncate output
-q, --quiet=false Only show numeric IDs
例:
$ sudo docker p_w_picpaths # , $ sudo docker p_w_picpaths -a # , $ sudo docker p_w_picpaths ubuntu # docker ubuntu REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 12.04 ebe4be4dd427 4 weeks ago 210.6 MB
ubuntu 14.04 e54ca5efa2e9 4 weeks ago 276.5 MB
ubuntu 14.04-ssh 6334d3ac099a 7 weeks ago 383.2 MB
4.6 docker rmi
1つ以上のミラーを削除
$ sudo docker rmi --help
Usage: docker rmi IMAGE [IMAGE...] Remove one or more p_w_picpaths
-f, --force=false Force removal of the p_w_picpath # --no-prune=false Do not delete untagged parents #
4.7 docker run
$ sudo docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run a command in a new container
-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 -d, --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 p_w_picpath # ? --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 -v, --volume=[] Bind mount a volume (e.g., from the host: -v /host:/container, from docker: -v /container) # --volumes-from=[] Mount volumes from the specified container(s) # -w, --workdir="" Working directory inside the container #
例:
$ sudo docker p_w_picpaths ubuntu
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 e54ca5efa2e9 4 weeks ago 276.5 MB
... ... $ sudo docker run -t -i -c 100 -m 512MB -h test1 -d --name="docker_test1" ubuntu /bin/bash # cpu 100, 512MB, test1, docker_test1 bash a424ca613c9f2247cd3ede95adfbaf8d28400cbcb1d5f9b69a7b56f97b2b52e5 $ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a424ca613c9f ubuntu:14.04 /bin/bash 6 seconds ago Up 5 seconds docker_test1 $ sudo docker attach docker_test1
root@test1:/# pwd /
root@test1:/# exit exit
cpu優先度について:
By default all groups have 1024 shares. A group with 100 shares will get a ~10% portion of the CPU time -archlinux cgroups
4.8 docker start|stop|kill... ...
dockerstart|stop|kill|restart|pause|unpause|rm|commit|inspect|logs
転載先:https://blog.51cto.com/lishenggui/1926553