参考地址:https://www.imooc.com/article/details/id/25228

操作系统Centos7

1、替换yum源为阿里云yum源;

  

//备份yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup //下载阿里yunyum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo //清除yum缓存
yum clean all //生成yum缓存
yum makecache

2、安装docker

  查看yum可以安装的docker,命令:yum list |grep docker

  

  执行安装命令:yum install docker

  安装完成之后,查看已经安装的docker,命令:yum list installed |grep docker

可以看出,安装docker需要三个包,见上图

3、添加开机启动

  命令:systemctl enable docker.service

4、启动docker

  命令:systemctl start docker.service

  启动失败,报错信息,查看命令:journalctl -xe,具体错误信息见下图:

此linux的内核中的SELinux不支持 overlay2 graph driver ,解决方法有两个,要么启动一个新内核,要么就在docker里禁用selinux,--selinux-enabled=false
修改文件,/etc/sysconfig/docker,在--selinux-enabled后面添加=false即可!具体修改见下图

重启docker,命令:systemctl restart docker.service

查看docker信息,命令:docker info
[root@localhost ~]# docker info
Containers:
Running:
Paused:
Stopped:
Images:
Server Version: 1.13.
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: journald
Cgroup Driver: systemd
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: docker-runc runc
Default Runtime: docker-runc
Init Binary: /usr/libexec/docker/docker-init-current
containerd version: (expected: aa8187dbd3b7ad67d8e5e3a15115d3eef43a7ed1)
runc version: e9c345b3f906d5dc5e8100b05ce37073a811c74a (expected: 9df8b306d01f59d3a8029be411de015b7304dd8f)
init version: 5b117de7f824f3d3825737cf09581645abbe35d4 (expected: 949e6facb77383876aeff8a6944dde66b3089574)
Security Options:
seccomp
WARNING: You're not using the default seccomp profile
Profile: /etc/docker/seccomp.json
Kernel Version: 3.10.-.el7.x86_64
Operating System: CentOS Linux (Core)
OSType: linux
Architecture: x86_64
Number of Docker Hooks:
CPUs:
Total Memory: 2.731 GiB
Name: localhost.localdomain
ID: NDA4:FMH4:OVC2:HARD:3Q4V:ZWIE:UTJU:YVR3:AFEE:FOBN:54NL:GXGU
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/
Live Restore Enabled: false
Registries: docker.io (secure)

Hello World

下面,我们通过最简单的 image 文件"hello world",感受一下 Docker。

因为国内连接 Docker 的官方仓库很慢,因此我们在日常使用中会使用Docker 中国加速器。通过 Docker 官方镜像加速,中国区用户能够快速访问最流行的 Docker 镜像。该镜像托管于中国大陆,本地用户现在将会享受到更快的下载速度和更强的稳定性,从而能够更敏捷地开发和交付 Docker 化应用。

Docker 中国官方镜像加速可通过registry.docker-cn.com访问。该镜像库只包含流行的公有镜像,私有镜像仍需要从美国镜像库中拉取。

修改系统中docker对应的配置文件即可,如下:

vi  /etc/docker/daemon.json
#添加后
{ "registry-mirrors": ["https://registry.docker-cn.com"], "live-restore": true}

也可以替换成网易的镜像地址

{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}

我们选择用网易的镜像地址。

运行下面的命令,将 image 文件从仓库抓取到本地。

docker pull library/hello-world

上面代码中,docker image pull是抓取 image 文件的命令。library/hello-world是 image 文件在仓库里面的位置,其中library是 image 文件所在的组,hello-world是 image 文件的名字。

抓取成功以后,就可以在本机看到这个 image 文件了。

查看下载的镜像,命令:docker images

[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest e38bc07ac18e weeks ago 1.85 kB

运行hello-world镜像,命令:docker run hello-world

[root@localhost docker]# 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命令外,Docker还有一些其它常用的命令

拉取docker镜像

docker pull image_name

查看宿主机上的镜像,Docker镜像保存在/var/lib/docker目录下:

docker images

删除镜像

docker rmi  docker.io/tomcat:7.0.77-jre7   或者  docker rmi b39c68b7af30

查看当前有哪些容器正在运行

docker ps

查看所有容器

docker ps -a

启动、停止、重启容器命令:

docker start container_name/container_iddocker stop container_name/container_iddocker restart container_name/container_id

后台启动一个容器后,如果想进入到这个容器,可以使用attach命令:

docker attach container_name/container_id

删除容器的命令:

docker rm container_name/container_id

查看当前系统Docker信息

docker info

从Docker hub上下载某个镜像:

docker pull centos:latestdocker pull centos:latest

执行docker pull centos会将Centos这个仓库下面的所有镜像下载到本地repository。

docker环境搭建的更多相关文章

  1. centos7系统下 docker 环境搭建

    运行环境: VMware Workstation Pro 在虚拟机中安装centos7系统, 选择最小安装, 网络连接方式选择的桥接(与宿主机在同一IP段)centos7一定要安装64位, docke ...

  2. win7下docker环境搭建nginx+php-fpm+easyswoole+lavarel+mysql开发环境

    win7环境基础在上一篇win7下docker环境搭建nginx+php-fpm+easyswoole开发环境中已经详细叙述搭建完成 本篇文章将叙述如何在上述基础上搭建laravel开发环境,这个其实 ...

  3. Docker环境搭建以及基本操作

    Docker环境搭建以及基本操作 Docker环境基本搭建: 基础环境:Centos 7.4        IP:192.168.30.117 [root@docker ~]# cat /etc/re ...

  4. Docker 环境搭建(RedHat 7)

    Docker 环境搭建(RedHat 7): CentOS7 下载 http://mirrors.sohu.com/centos/7/isos/x86_64/ 装载镜像文件 安装Linux 7, 参考 ...

  5. 【架构】docker环境搭建mysql主从

    序 本文主要研究怎么在docker上搭建mysql的主从.因为在单机搭建mysql多实例然后再配主从,感觉太痛苦了,环境各有不同,配置各不大相 同,从网上找搭建方法,试了半天也没成功,最后也没耐心调试 ...

  6. ClusterControl docker 环境搭建

    ClusterControl 是一款比较强大的数据库管理平台,包含了丰富的数据库管理功能. 我们可以用来方便的进行数据管理 测试使用docker-compose 管理 环境准备 docker-comp ...

  7. docker环境搭建centos+jdk+tomcat_CENTOS篇

    前言 (1)写在前面的话,鉴于在linux或类unix系统中安装jdk+tomcat等环境,没有什么经验,所以选择在docker容器中安装之,以防止安装失败无法恢复系统 (2)需要下载对应的系统的do ...

  8. win7下docker环境搭建nginx+php-fpm+easyswoole开发环境

    基础的环境已在文章nginx.php-fpm.swoole HTTP/TCP压测对比中搭建了,现在是在这个基础上在搭建easyswoole开发环境 主要要修改的地方是dnmp包里面的docker-co ...

  9. Mesos+Zookeeper+Marathon+Docker环境搭建

    相关理论请参考:https://www.cnblogs.com/Bourbon-tian/p/7155054.html,本文基于https://www.cnblogs.com/Bourbon-tian ...

  10. 【Docker】Windows下docker环境搭建及解决使用非官方终端时的连接问题

    背景 时常有容器方面的需求,经常构建调试导致测试环境有些混乱,所以想在本地构建一套环境,镜像调试稳定后再放到测试环境中. Windows Docker 安装 安装docker toolbox 博主的电 ...

随机推荐

  1. pjsip 播放音视频

    http://blog.csdn.net/leixiaohua1020/article/details/40246783 onCallMediaState回调里,解码方向,获取ci.media[i]. ...

  2. mssql sqlserver 批量删除所有存储过程的方法分享

    转自:http://www.maomao365.com/?p=6864 摘要: 下文讲述采用sql脚本批量删除所有存储过程的方法,如下所示: 实验环境:sqlserver 2008 R2 平常使用sq ...

  3. irc 关键操作

    IRC 客户端: Textual 5 HexChat  IRC 用户密码常用命令: 用户密码: 忘记密码 如果太长时间没登录IRC,难免会忘记密码,那IRC有重置密码的功能吗?当然有,不过也是通过命令 ...

  4. Python: 遍历

    ======================遍历列表========================# 直接遍历list: for elem in list: pass # 通过索引获取 for i ...

  5. LeetCode算法题-Delete Node in a Linked List(Java实现)

    这是悦乐书的第197次更新,第204篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第60题(顺位题号是235).编写一个函数来删除单链表中的节点(尾部除外),只允许访问该 ...

  6. "敏捷革命"读书笔记

    最近看可一本书 书名叫<敏捷革命>外国著作中文翻译 本来想自己总结读后感但是本书后面都有本章的总结,所以下面都已摘抄为主,以备之后快速浏览 第一章 世界的运作方式已经打破 规划是有用的,而 ...

  7. baidu.com跳转www.baidu.com

    打开git bash,输入 curl baidu.com,收到返回 <html> <meta http-equiv="refresh" content=" ...

  8. PostgreSQL条件表达式 case when then end

    例: SELECT CASE WHEN (store_size <= (100)::NUMERIC) THEN '小店'::TEXT WHEN (store_size >= (200):: ...

  9. UVA12569-Planning mobile robot on Tree (EASY Version)(BFS+状态压缩)

    Problem UVA12569-Planning mobile robot on Tree (EASY Version) Accept:138  Submit:686 Time Limit: 300 ...

  10. 解决y7000笔记本ubuntu18.04下 休眠挂起后唤醒花屏

    定位问题,切换到核显后发现一点问题也没有,基本确定是显卡驱动的问题 但是由于配置环境比较复杂,不想重新装N卡驱动,所以另寻方法 sudo gedit /etc/default/grub 修改前 # I ...