docker容器一简介与部署

一、Docker简介

1.docker概述

  • Docker是一个开发,运输和运行应用程序的开放平台。Docker可以将应用程序与基础架构分离,以便快速交付软件。使用Docker,可以像管理应用程序一样管理基础架构。通过利用Docker的方法快速发送,测试和部署代码,可以显着减少编写代码和在生产中运行代码之间的延迟。
  • docker官网https://docs.docker.com/get-started/

2.docker使用场景

  • web应用的自动化打包和发布;
  • 自动化测试和持续集成、发布;
  • 在服务型环境中部署和调整数据库或其他的后台应用;
  • 从头编译或者扩展现有的OpenShift或Cloud Foundry平台来搭建自己的PaaS环境。

3.docker与openstack对比

类别 docker openstack
部署难度 非常简单 组件多,部署复杂
启动速度 秒级 分钟级
执行性能 和物理系统几乎一致 VM会占用一些资源
镜像体积 镜像是MB级别 虚拟机镜像GB级别
管理效率 管理简单 组件互相依赖,管理复杂
隔离性 隔离性高 彻底隔离
可管理性 单进程 完整的系统管理
网络连接 比较弱 借助neutron可以灵活组件各类网络架构

二、安装docker

1.系统环境

[root@docker-server ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@docker-server ~]# uname -r
3.10.0-327.el7.x86_64

2.安装所需的包

[root@docker-server ~]# yum install -y yum-utils   device-mapper-persistent-data lvm2

3.添加docker仓库

[root@docker-server ~]# yum-config-manager --add-repo     https://download.docker.com/linux/centos/docker-ce.repo
[root@docker-server ~]# ll /etc/yum.repos.d/docker-ce.repo     
-rw-r--r--. 1 root root 2424 Sep  9 05:31 /etc/yum.repos.d/docker-ce.repo

4.启用仓库

[root@docker-server ~]# yum-config-manager --enable docker-ce-edge
[root@docker-server ~]# yum-config-manager --enable docker-ce-test

5.指定版本安装docker-ce

[root@docker-server ~]#yum list docker-ce --showduplicates | sort -r###查看版本列表
[root@docker-server ~]# yum install docker-ce-18.06.1.ce -y 

6. 配置镜像加速器

  • 由于国内特殊的网络环境,往往我们从DockerHub中拉取镜像并不能成功,而且速度特别慢,那么我们可以给Docker配置一个国内的registry mirror
    登录阿里云,使用阿里云的镜像加速器
    这里写图片描述
[root@docker-server ~]# cat >> /etc/docker/daemon.json <<-EOF
{
  "registry-mirrors": ["https://tmgyk4cn.mirror.aliyuncs.com"]
}
EOF

7.启动docker

[root@docker-server ~]# systemctl enable docker
[root@docker-server ~]# systemctl start docker

8.验证

[root@docker-server ~]#  docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:23:03 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:25:29 2018
  OS/Arch:          linux/amd64
  Experimental:     false
[root@localhost ~]# docker run hello-world  

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

猜你喜欢

转载自blog.csdn.net/liang_operations/article/details/82626433