设为首页 收藏本站
查看: 1275|回复: 0

[经验分享] Docker的概念及基本用法

[复制链接]

尚未签到

发表于 2017-12-7 08:49:13 | 显示全部楼层 |阅读模式
  Docker是PaaS供应商dotCloud开源的一个基于LXC 的高级容器引擎,源代码托管在 GitHub 上, 基于Go语言开发并遵从Apache 2.0协议开源。Docker提供了一种在安全、可重复的环境中自动部署软件的方式。
  关于Docker的架构,查看官方介绍。
  Docker致力于提供:
  1. 简单、轻量的建模方式
  2. 开发运维职责的逻辑分离,降低开发与生产环境的不一致性。
  3. 快速高效的开发生命周期
  4. 面向服务的架构,推荐单个容器只运行一个应用程序或进程

Docker组件
  Docker核心组件:
  Docker客户端和服务器
  Docker镜像
  Registry
  Docker容器

  Docker技术组件:
  1) libcontainer,一个原生的linux 容器格式
  2) Linux 内核的命名空间(namespace),用户隔离文件系统、进程和网络

Docker安装和启动

1 安装
  如下安装适用于Redhat操作系统。
  安装方式有两种:使用yum在线安装,或者使用安装包安装。
  使用yum方式安装



//1 更新yum 安装包index
$ sudo yum makecache fast

//2. 安装docker最新版本
$ sudo yum -y install docker-engine

// 或者安装特定版本
$ yum list docker-engine.x86_64  --showduplicates |sort -r
$ sudo yum -y install docker-engine-<VERSION_STRING>
  使用安装包安装



1 下载对应操作系统版本的包,比如对应RHCE的rpm包
2 安装
$ sudo yum install package.rpm

2 Docker启动



$ sudo systemctl start docker
  验证Docker是否安装成功



$ sudo docker run hello-world
  使用docker version查看版本
DSC0000.gif

  更多参考官方文档。

基本命令

1 查看Docker所有的命令



docker

DSC0001.gif


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
2 查看指定命令的帮助
  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 // 查看到已经停止的容器
sample
3 容器管理
  docker run:  命令用来创建运行容器
  docker ps:
  用来查看正在运行的容器列表
  几个最常用的参数:


  • -a:查看所有容器,含停止运行的
  • -l:查看刚启动的容器
  • -q:只显示容器ID
  docker start:  启动容器
  我们可以通过 docker attach 连接到某个正在运行的container。
  docker stop: 停止容器
  docker inspect:  查看Docker容器或镜像的一些内部信息
  docker rm:  删除容器操作,默认不可以删除运行的容器,但提供了强制删除的参数-f
  docker top: 查看容器中运行的进程信息,显示容器中进程的PID,UID,PPID,时间,tty等信息。

4 镜像管理
  docker images: 查看镜像列表
  其中:


  • REPOSITORY:仓库名称
  • TAG:标签名,一个仓库可以有若干个标签对应不同的镜像,默认都是latest
  • IMAGE ID:镜像ID
  • CREATED:创建时间,注意不是本地的pull时间
  • SIZE:镜像大小
  docker pull: 获取镜像, 从Docker Hub上pull某一个镜像
  创建镜像: 最常用的是写一个Dockerfile,从Dockerfile里创建新的镜像。
  清理镜像:使用docker rmi来删除镜像,删除镜像前要用docker rm删除对应的container

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-421565-1-1.html 上篇帖子: 使用镜像仓库托管自己构建的Docker镜像 下篇帖子: 制作docker-jdk7-zookeeper镜像(非集群版)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表