Docker是PaaS供应商dotCloud开源的一个基于LXC 的高级容器引擎,源代码托管在 GitHub 上, 基于Go语言开发并听从Apache 2.0协议开源。Docker提供了一种在安全、可重复的环境中自动部署软件的方式。node
关于Docker的架构,查看官方介绍。 linux
Docker致力于提供:docker
1. 简单、轻量的建模方式安全
2. 开发运维职责的逻辑分离,下降开发与生产环境的不一致性。服务器
3. 快速高效的开发生命周期网络
4. 面向服务的架构,推荐单个容器只运行一个应用程序或进程架构
Docker核心组件:app
Docker客户端和服务器运维
Docker镜像socket
Registry
Docker容器
Docker技术组件:
1) libcontainer,一个原生的linux 容器格式
2) Linux 内核的命名空间(namespace),用户隔离文件系统、进程和网络
以下安装适用于Redhat操做系统。
安装方式有两种:使用yum在线安装,或者使用安装包安装。
使用yum方式安装
1 //1 更新yum 安装包index 2 $ sudo yum makecache fast 3 4 //2. 安装docker最新版本 5 $ sudo yum -y install docker-engine 6 7 // 或者安装特定版本 8 $ yum list docker-engine.x86_64 --showduplicates |sort -r 9 $ sudo yum -y install docker-engine-<VERSION_STRING>
使用安装包安装
1 下载对应操做系统版本的包,好比对应RHCE的rpm包 2 安装 $ sudo yum install package.rpm
$ sudo systemctl start docker
验证Docker是否安装成功
$ sudo docker run hello-world
使用docker version查看版本
更多参考官方文档。
docker
Usage: docker COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/Users/liuchun/.docker") -D, --debug Enable debug mode --help Print usage -H, --host list Daemon socket(s) to connect to (default []) -l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/Users/liuchun/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/Users/liuchun/.docker/cert.pem") --tlskey string Path to TLS key file (default "/Users/liuchun/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: checkpoint Manage checkpoints container Manage containers image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker volume Manage volumes 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 between a container and the local filesystem create Create a new container deploy Deploy a new stack or update an existing stack 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 Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command.
docker command --help
,例如启动命令docker run --help
Docker配置服务
RHCE7 参考https://docs.docker.com/engine/admin/
运行一条命令的example
# docker run busybox echo "Hello, this is new msg" # docker ps //查看容器 # docker ps -a // 查看到已经中止的容器
docker run: 命令用来建立运行容器
docker ps:
用来查看正在运行的容器列表
几个最经常使用的参数:
-a
:查看全部容器,含中止运行的-l
:查看刚启动的容器-q
:只显示容器IDdocker start: 启动容器
咱们能够经过 docker attach
链接到某个正在运行的container。
docker stop: 中止容器
docker inspect: 查看Docker容器或镜像的一些内部信息
docker rm: 删除容器操做,默认不能够删除运行的容器,但提供了强制删除的参数-f
docker top: 查看容器中运行的进程信息,显示容器中进程的PID,UID,PPID,时间,tty等信息。
docker images: 查看镜像列表
其中:
latest
docker pull: 获取镜像, 从Docker Hub上pull某一个镜像
建立镜像: 最经常使用的是写一个Dockerfile,从Dockerfile里建立新的镜像。
清理镜像:使用docker rmi来删除镜像,删除镜像前要用docker rm删除对应的container