说明:本文也是参考互联网上的文章写的,感谢相关作者的贡献。

操作系统

64位CentOS Linux release 7.2.1511 (Core)

配置好IP:192.168.1.160

修改yum源

目的是提升对docker的下载速度。

1.备份你的原镜像文件,以免出错后可以恢复。

[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.下载新的CentOS-Base.repo 到/etc/yum.repos.d/

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.运行yum makecache生成缓存

[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache

安装Docker

[root@localhost ~]# yum -y install docker-io

要稍等几分钟才能安装好。网速快的话几十秒吧。

启动Docker

[root@localhost ~]# systemctl start docker

发现会报错:

Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

按照提示执行:

[root@localhost ~]# systemctl status docker.service

会有提示信息如下:

● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 三 -- :: CST; 52s ago
Docs: http://docs.docker.com
Process: ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=/FAILURE)
Main PID: (code=exited, status=/FAILURE) 5月 :: localhost.localdomain systemd[]: Starting Docker Application Container Engine...
5月 :: localhost.localdomain dockerd-current[]: time="2018-05-02T23:34:45.527821208+08:00" level=warning msg="could not change group /var/run/...t found"
5月 :: localhost.localdomain dockerd-current[]: time="2018-05-02T23:34:45.532650572+08:00" level=info msg="libcontainerd: new containerd proce...: 14421"
5月 :: localhost.localdomain dockerd-current[]: time="2018-05-02T23:34:46.539484373+08:00" level=warning msg="overlay2: the backing xfs filesystem is ...
5月 :: localhost.localdomain dockerd-current[]: Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel....d=false)
5月 :: localhost.localdomain systemd[]: docker.service: main process exited, code=exited, status=/FAILURE
5月 :: localhost.localdomain systemd[]: Failed to start Docker Application Container Engine.
5月 :: localhost.localdomain systemd[]: Unit docker.service entered failed state.
5月 :: localhost.localdomain systemd[]: docker.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

红色部分告诉我们此linux的内核中的SELinux不支持 overlay2 graph driver,解决方法有两个,要么启动一个新内核,要么就在docker里禁用selinux,设置--selinux-enabled=false。我们采用第二种方式。

[root@localhost ~]# vi /etc/sysconfig/docker

然后将--selinux-enabled设置成false,保存并退出。

# /etc/sysconfig/docker

# Modify these options if you want to change the way the docker daemon runs
OPTIONS='--selinux-enabled=false --log-driver=journald --signature-verification=false'
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi
# ......省略N行

重新启动

[root@localhost ~]# systemctl start docker

查看版本号

[root@localhost ~]# docker -v

Docker version 1.13.1, build 774336d/1.13.1

至此docker启动成功

修改Docker镜像加速器

因为国外的docker镜像访问太慢,所以我们需要修改成阿里云的docker镜像。这样从国内镜像拉取速度会快点。

1.打开阿里云docker仓库地址https://dev.aliyun.com/search.html

2.淘宝账号即可登录,登录后点击自己的管理中心。

3.点击管理中心左侧菜单栏的“镜像加速器”,右边面板会有你的加速地址,面板下面有详细设置步骤。如下图:

[root@localhost ~]# vi /etc/docker/daemon.json

将下面整行字符拷贝进去,保存并退出。

"registry-mirrors": ["https://njrds9qc.mirror.aliyuncs.com"]

刷新daemon

[root@localhost ~]# systemctl daemon-reload

重启docker

[root@localhost ~]# systemctl restart docker

拉取镜像

以hello-world为例

[root@localhost tmp]# docker pull hello-world
Using default tag: latest
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for docker.io/hello-world:latest

表示成功拉取

运行镜像

[root@localhost tmp]# 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:
. The Docker client contacted the Docker daemon.
. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
. 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/engine/userguide/

成功运行。

简单操作命令

镜像

docker pull 镜像名称[:版本]

拉取镜像,如果版本为空,则拉取最新的版本

docker run 镜像名称或ID

运行镜像,创建容器

docker run -it 镜像名称或ID

运行镜像,创建容器,并进入该容器。

-i表示以交互模式运行容器,通常与 -t 同时使用;

-t表示为容器重新分配一个伪输入终端,通常与 -i 同时使用;

另外还有很多参数,可参考http://www.runoob.com/docker/docker-run-command.html

docker rmi 镜像名称或ID

根据名称或ID删除镜像

容器

docker ps

列出容器

-a显示所有的容器,包括未运行的

-q 静默模式,只显示容器编号,通常和-a一起使用,docker ps -aq

docker rm 容器名称或ID

根据名称或者ID删除容器,如果带上参数-f,表示强制删除正在运行的容器

docker rm $(docker ps -aq)

表示删除所有容器

docker start 容器名称或ID

根据名称或者ID启动容器

docker stop 容器名称或ID

根据名称或者ID停止容器

docker attach id

进入某个容器(使用exit退出后容器也跟着停止运行)

docker exec -ti id

启动一个伪终端以交互式的方式进入某个容器(使用exit退出后容器不停止运行)

centos7 docker安装和使用_入门教程的更多相关文章

  1. WordPress安装:零基础入门教程

    WordPress安装:零基础入门教程 1主机空间要求要运行 WordPress,主机空间需满足以下条件.不过现在网络上的空间基本都可以,而且还让你随意定制Php和Mysql版本,至于空间和数据库大小 ...

  2. centos7 docker 安装配置

    docker快速入门测试 ########################################## #docker安装配置 #环境centos7 #配置docker阿里源 echo '#D ...

  3. GDI+_入门教程【一】

    GDI For VisualBasic6.0 [一]文件下载:GDI+ For VB6[一] 简单绘图实例演示百度网盘 1 '以下为作者[vIsiaswx]的教程 '(该教程发布的原地址已无法访问,此 ...

  4. centos7 docker 安装 mysql5.7.24 导入12G的sql

    先在CentOS7里面安装docker Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker .通过 uname - ...

  5. centos7+docker 安装和部署crawlab分布式爬虫平台,并使用docker-compose管理docker

    1.先决条件centos7+docker最新版本 sudo yum updat 2.配置一下镜像源,创建/etc/docker/daemon.conf文件,在其中输入如下内容 { "regi ...

  6. centos7 docker安装

    Docker分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施.容器.插件等 社区版按照stable和edge两种 ...

  7. 4.centos7 docker 安装

    参考这个文档进行安装docker: http://www.runoob.com/docker/centos-docker-install.html 开机启动 systemctl enable dock ...

  8. Centos7 Docker 安装笔记

    1. docker官方文档地址:https://docs.docker.com/ 2. centos版本号查看命令:uname -a    centos7.3版本 3. 直接yum -install ...

  9. 【URLOS开发入门】docker官方系统镜像——Alpine入门教程

    我们在进行URLOS应用开发时,经常会用到一些基础系统镜像,如:ubuntu.CentOS.Debian等,我们可以通过docker pull命令直接拉取官方镜像. root@ubuntu:~# do ...

随机推荐

  1. C#基础学习之StreamReader和StreamWriter

    StreamReader和StreamWriter操作字符的 FileStream操作字节的 //使用StreamReader读取文件 using (StreamReader sr=new Strea ...

  2. 项目中遇到的问题:Gradle传递性依赖冲突

    问题描述: 在调用别人接口时,由于他们接口做了拦截处理在使用RestTemplate调用时必须要使用@Qualifier("他们封装好的类"),需要导入jar包 gradle方式导 ...

  3. poj1067

    题意:有两堆石子,两人轮流取,每次可以取一堆中的任意个,或两堆中取相同多个.谁先取光所有堆谁赢.问先手能否获胜. 分析:威佐夫博弈,如果是奇异态则先手输,否则先手赢.直接套用公式判断是否为奇异态,设第 ...

  4. vue总结 08状态管理vuex

      状态管理 类 Flux 状态管理的官方实现 由于状态零散地分布在许多组件和组件之间的交互中,大型应用复杂度也经常逐渐增长.为了解决这个问题,Vue 提供 vuex:我们有受到 Elm 启发的状态管 ...

  5. FFmpeg命令行工具和批处理脚本进行简单的音视频文件编辑

    FFmpeg_Tutorial FFmpeg工具和sdk库的使用demo 一.使用FFmpeg命令行工具和批处理脚本进行简单的音视频文件编辑 1.基本介绍 对于每一个从事音视频技术开发的工程师,想必没 ...

  6. Luogu P2310 【loidc,看看海】

    各位大佬都用的排序和杨颙大定理,蒟蒻的我怎么也不会做(瑟瑟发抖),那么,就来一发主席树吧.我们知道线段树可以维护区间,平衡树可以维护值域那么,我们可以用线段树套平衡树来解决这个区间值域的问题线段树套平 ...

  7. Spring cloud Feign 调用端不生效

    如果提供方的接口经过测试是没问题的话. 消费方启动类加上@EnableFeignClients 注意定义的接口如果不和启动类在同一个包路径下,需要加basePackages 即:@EnableFeig ...

  8. babel转换不了有些es6

    bable只转换新语法 不支持新的全局变量如promise async等等,可以使用babel-polyfilll来兼容

  9. SQL SERVER 断开所有连接(转)

    通过sql server management studio对数据进行管理,比如数据库改名等,经常遇到有正在运行的连接,以致无法操作,这时候断掉所有的连接很有必要.代码如下:(会断掉某个库的所有连接, ...

  10. Python学习笔记:import sys模块(argv、path、platform、exit)

    sys模块是Python标准库中自带的一个模块. sys模块包括了一组非常实用的服务,内含很多函数方法和变量,用来处理Python运行时配置以及资源,从而可以与当前程序之外的系统环境交互,如:Pyth ...