一、docker基础

docker是什么?

为什么用docker?

虚拟化与docker :容器提供了基于进程的隔离,而虚拟机提供了资源的完全隔离容器使用宿主操作系统的内核,而虚拟机使用独立的内核

 

二、基本概念:

Dockerfile

docker镜像

Docker容器

Docker仓库

docker 的安装与配置 

软件环境规划

 

 

 

三、命令:

 1  docker version

搜索可用docker镜像: docker search tutorial

 

 

 

1为宿主机安装 docker

CentOS 7 中 Docker 的安装

Docker 软件包已经包括在默认的 CentOS-Extras 软件源里。因此想要安装 docker,只需要运行下面的 yum 命令:

  1. [root@localhost ~]# yum install docker

启动 Docker 服务

安装完成后,使用下面的命令来启动 docker 服务,并将其设置为开机启动:

采用CentOS 7中支持的新式 systemd 语法,如下:

  1. [root@localhost ~]# systemctl start docker.service
  2. [root@localhost ~]# systemctl enable docker.service

下载官方的 CentOS 镜像到本地

docker pull centos

删除本地镜像

docker rmi  镜像名/ID

 

查看CentOS 镜像已经被获取:

docker images docker

运行一个 Docker 容器创建新容器:

  1. [root@localhost ~]# docker run -i -t --privileged --net=”host” --name ovcer_the_container centos /bin/bash
  2. [root@dbf66395436d /]#

我们可以看到,CentOS 容器已经被启动,并且我们得到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。

docker run:启动container

ubuntu:你想要启动的image

-t:进入终端

-i:得一个交互式的连接,通过获取container的输入

/bin/bash:在container中启动一个bash shell

启动时Docker中容器的命名

  Docker在创建容器时会自动为容器生成一个随机的名称。那么如果我们想在创建一个容器时指定该容器的名称可以使用如下命令:

  [root@localhost ~]# docker run --name ovcer_the_container -i -t ubuntu /bin/bash

  root@1ce9f640478d:/#

 

 

若要断开与容器的连接:

输入 exit。

显示当前正在运行容器的列表

docker ps

显示系统所有 容器列表:docker ps -a

rm 删除一个或多个容器

Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]Remove one or more containers

  -f,--force=falseForce removal of running container

  -l,--link=falseRemove the specified link andnot the underlying container

  -v,--volumes=falseRemove the volumes associated with the container

比如 docker rm /redis

 

diff命令查看容器的变化信息

xxx@ubuntu:~$ docker diff newcontent

C /root

A /root/.bash_history

A /test.txt

 

从主机进入容器:

参考:http://blog.csdn.net/woshiluahuo/article/details/52239407

Docker attach xxxxxx进入后退出,会导致容器退出

建议使用 docker ps 找到你要进入的containerid,然后用 docker exec 执行一个 bash

如:docker exec -it 40c330755e61 /bin/bash

这样你就进到这个container 里面了,这个bash退出也不会影响之前 docker run 启动的 bash

 

后台启动docker run -d ubuntu:15.10 /bin/s

启动docker容器:docker start {id}

 

保存容器,生成新的镜像:docker commit 698 learn/ping

 

 

使用阿里云容器Hub加速Docker镜像下载

http://blog.csdn.net/evandeng2009/article/details/53893789

登录阿里云开发者平台http://dev.aliyun.com/,进入加速器页面

 

 

 

 

 

Docker中无法使用systemctl的问题