<从Docker到Kubernetes之技术实战>教程作业(二)

<从Docker到Kubernetes之技术实战>教程作业(二)

一. 列出docker所有的命令和含义

二. docker run命令的中的参数以及含义

Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Run a command in a new container

-a, --attach=[] Attach to STDIN, STDOUT or STDERR
--add-host=[] Add a custom host-to-IP mapping (host:ip)
--blkio-weight=0 Block IO (relative weight), between 10 and 1000
-c, --cpu-shares=0 CPU shares (relative weight)
--cap-add=[] Add Linux capabilities
--cap-drop=[] Drop Linux capabilities
--cgroup-parent= Optional parent cgroup for the container
--cidfile= Write the container ID to the file
--cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota=0 Limit CPU CFS (Completely Fair Scheduler) quota
--cpuset-cpus= CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems= MEMs in which to allow execution (0-3, 0,1)
-d, --detach=false Run container in background and print container ID
--device=[] Add a host device to the container
--disable-content-trust=true Skip image verification
--dns=[] Set custom DNS servers
--dns-search=[] Set custom DNS search domains
-e, --env=[] Set environment variables
--entrypoint= Overwrite the default ENTRYPOINT of the image
--env-file=[] Read in a file of environment variables
--expose=[] Expose a port or a range of ports
--group-add=[] Add additional groups to join
-h, --hostname= Container host name
--help=false Print usage
-i, --interactive=false Keep STDIN open even if not attached
--ipc= IPC namespace to use
-l, --label=[] Set meta data on a container
--label-file=[] Read in a line delimited file of labels
--link=[] Add link to another container
--log-driver= Logging driver for container
--log-opt=[] Log driver options
--lxc-conf=[] Add custom lxc options
-m, --memory= Memory limit
--mac-address= Container MAC address (e.g. 92:d0:c6:0a:29:33)
--memory-swap= Total memory (memory + swap), '-1' to disable swap
--memory-swappiness=-1 Tuning container memory swappiness (0 to 100)
--name= Assign a name to the container
--net=default Set the Network mode for the container
--oom-kill-disable=false Disable OOM Killer
-P, --publish-all=false Publish all exposed ports to random ports
-p, --publish=[] Publish a container's port(s) to the host
--pid= PID namespace to use
--privileged=false Give extended privileges to this container
--read-only=false Mount the container's root filesystem as read only
--restart=no Restart policy to apply when a container exits
--rm=false Automatically remove the container when it exits
--security-opt=[] Security Options
--sig-proxy=true Proxy received signals to the process
-t, --tty=false Allocate a pseudo-TTY
-u, --user= Username or UID (format: [:])
--ulimit=[] Ulimit options
--uts= UTS namespace to use
-v, --volume=[] Bind mount a volume
--volume-driver= Optional volume driver for the container
--volumes-from=[] Mount volumes from the specified container(s)
-w, --workdir= Working directory inside the container

三. 为什么docker create 中不能有-d参数

docker create指令会create 一个container,但不启动. docker run指令会create 一个 container 并启动这个 container, 并执行指令. -d 的意思是在后台运行, docker run 有-d 表示在后台执行指令, 但 docker create 并不执行指令, 所以也就没有-d 的参数.

四. docker的image与container存放在什么路径下

mac 下使用 VirtualBox 启动


通过 pull images 的操作,对比前后文件夹大小,可以看到 image 存放在 /var/lib/docker/aufs

在 centos7 下的路径为: ** /var/lib/docker/devicemapper/devicemapper**

container的路径则是: /var/lib/docker/container

五. 使用至少5个docker 镜像并记录你的使用过程,如tomcat、 redis、 mysql

1.使用加速器:

curl -sSL https://get.daocloud.io/docker | sh 
sudo chkconfig docker on 
sudo systemctl start docker

2.拉取 images

centos:

dao pull centos

nginx:

docker pull daocloud.io/library/nginx:latest

Java:

docker pull daocloud.io/library/java:openjdk-8-jdk

Tomcat:

docker pull daocloud.io/daocloud/dao-tomcat:v7.0.55

Mysql:

docker pull daocloud.io/library/mysql:latest

本地的 images

3.运行容器

docker run -ti -p 80:80 daocloud.io/library/nginx:latest /bin/bash

进入容器中启动 nginx:

./usr/sbin/nginx

然后在宿主机上访问本机的80端口:

4.查看状态

使用 ctrl+p ctrl+q 回到宿主机

2015-12-19 13:23279