参考文档:http://dockone.io/article/101
环境:ubuntu 15.10 desktop 64bit
安装
sudo apt-get install docker.io
[说明]:docker和docket.io的关系
docker docker.io是docker在linux的包名
sudo docker info
sudo docker version
配置文件
/etc/default/docker
本地资源都存放在/var/lib/docker/目录下,其中:
container目录存放容器信息
graph目录存放镜像信息
aufs目录下存放具体的内容文件。
拉取镜像
格式:docket pull Registry_URL/repository:tag
$ sudo docker pull dl.dockerpool.com:5000/ubuntu:14.04
$ sudo docker pull ubuntu
其它命令:
l 显示镜像:sudo docker images
Ubuntu <wbr>安装和使用Docker容器
[解释]:相关源代码工作原理,请看这里
http://www.youkuaiyun.com/article/2014-12-15/2823143-Docker-image
l 重命名镜像:sudo docker tag repository repository_newname:tag
l 删除镜像:sudo docker rmi dl.dockerpool.com:5000/ubuntu:14.04
[个人理解]:IMAGE ID 才是镜像的唯一标识。而REPOSITORY和TAG的组合才是名称描述。
启动容器
格式:docker run 参数 repository:tag或者是image_id 想要执行的命令
sudo docker run --name=test_ubuntu -i -t dockerubuntu /bin/bash
root@9610717cf0fe:/#
至此,你已经进入到容器主机的shell终端了。
Ubuntu <wbr>安装和使用Docker容器
从上图中我们发现,在真实主机中和在容器主机中执行“uname -a”。结果除了计算机名称不一样,其它完全一样。这也是docker和传统VM虚拟机最大的不同。
其它更多细节请自行理解。
其它命令:
l 启动、重启、停止容器:sudo docker start|restart|stop container_id
l 重新进入到已启动的容器:sudo docker attach container_id
l 显示所有容量:$ sudo docker ps -a
Ubuntu <wbr>安装和使用Docker容器
9610717cf0fe:代表容器的ID
ubuntu:latest:创建容器的镜像
"/bin/bash":容器最后执行的命令
20 minutes ago:创建时间
Exited (0) 3 seconds ago:容器退出的状态
test_ubuntu:容器的名称
l 提交容量修改,形成新的镜像:
$ sudo docker commit 9610717cf0fe 0114ubuntu
格式:docker commit containet_id image_new_name
[个人理解]:镜像可以多次启动,形成不同ID的容器。这一点,类似于程序开发中的“类”和“实例”。而且不同ID的容器经过一系列操作配置后,可以“提交”成新的镜像。只不过目前,不同ID的容器里的操作,不能合并保存为同一个新的镜像。
l 在容器中安装软件包:
root@9610717cf0fe:/# apt-get update
root@9610717cf0fe:/# apt-get install vsftpd
l 删除已关闭的容器:$ sudo docker rm 9610717cf0fe
强制删除指定的容器:$ sudo docker rm -f containet_id
专题一:启动容量参数
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
-a, --attach=[] Attach to STDIN, STDOUT or STDERR
--add-host=[] Add a custom host-to-IP mapping (host:ip)
-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
--cpuset-cpus= CPUs 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
--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
-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
--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
--name= Assign a name to the container
--net=bridge Set the Network mode for the container
-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
-v, --volume=[] Bind mount a volume
--volumes-from=[] Mount volumes from the specified container(s)
-w, --workdir= Working directory inside the container
专题二:容量网络Host模式
sudo docker run --name=test_ubuntu --net=host -t -i 7c0b057fcd3b
--net=host
这样启动的容器,网络参数与宿主机一模一样。
环境:ubuntu 15.10 desktop 64bit
安装
sudo apt-get install docker.io
[说明]:docker和docket.io的关系
docker docker.io是docker在linux的包名
sudo docker info
sudo docker version
配置文件
/etc/default/docker
本地资源都存放在/var/lib/docker/目录下,其中:
container目录存放容器信息
graph目录存放镜像信息
aufs目录下存放具体的内容文件。
拉取镜像
格式:docket pull Registry_URL/repository:tag
$ sudo docker pull dl.dockerpool.com:5000/ubuntu:14.04
$ sudo docker pull ubuntu
其它命令:
l 显示镜像:sudo docker images
Ubuntu <wbr>安装和使用Docker容器
[解释]:相关源代码工作原理,请看这里
http://www.youkuaiyun.com/article/2014-12-15/2823143-Docker-image
l 重命名镜像:sudo docker tag repository repository_newname:tag
l 删除镜像:sudo docker rmi dl.dockerpool.com:5000/ubuntu:14.04
[个人理解]:IMAGE ID 才是镜像的唯一标识。而REPOSITORY和TAG的组合才是名称描述。
启动容器
格式:docker run 参数 repository:tag或者是image_id 想要执行的命令
sudo docker run --name=test_ubuntu -i -t dockerubuntu /bin/bash
root@9610717cf0fe:/#
至此,你已经进入到容器主机的shell终端了。
Ubuntu <wbr>安装和使用Docker容器
从上图中我们发现,在真实主机中和在容器主机中执行“uname -a”。结果除了计算机名称不一样,其它完全一样。这也是docker和传统VM虚拟机最大的不同。
其它更多细节请自行理解。
其它命令:
l 启动、重启、停止容器:sudo docker start|restart|stop container_id
l 重新进入到已启动的容器:sudo docker attach container_id
l 显示所有容量:$ sudo docker ps -a
Ubuntu <wbr>安装和使用Docker容器
9610717cf0fe:代表容器的ID
ubuntu:latest:创建容器的镜像
"/bin/bash":容器最后执行的命令
20 minutes ago:创建时间
Exited (0) 3 seconds ago:容器退出的状态
test_ubuntu:容器的名称
l 提交容量修改,形成新的镜像:
$ sudo docker commit 9610717cf0fe 0114ubuntu
格式:docker commit containet_id image_new_name
[个人理解]:镜像可以多次启动,形成不同ID的容器。这一点,类似于程序开发中的“类”和“实例”。而且不同ID的容器经过一系列操作配置后,可以“提交”成新的镜像。只不过目前,不同ID的容器里的操作,不能合并保存为同一个新的镜像。
l 在容器中安装软件包:
root@9610717cf0fe:/# apt-get update
root@9610717cf0fe:/# apt-get install vsftpd
l 删除已关闭的容器:$ sudo docker rm 9610717cf0fe
强制删除指定的容器:$ sudo docker rm -f containet_id
专题一:启动容量参数
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
-a, --attach=[] Attach to STDIN, STDOUT or STDERR
--add-host=[] Add a custom host-to-IP mapping (host:ip)
-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
--cpuset-cpus= CPUs 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
--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
-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
--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
--name= Assign a name to the container
--net=bridge Set the Network mode for the container
-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
-v, --volume=[] Bind mount a volume
--volumes-from=[] Mount volumes from the specified container(s)
-w, --workdir= Working directory inside the container
专题二:容量网络Host模式
sudo docker run --name=test_ubuntu --net=host -t -i 7c0b057fcd3b
--net=host
这样启动的容器,网络参数与宿主机一模一样。