Docker
--------------------- 本文来自 叶云轩 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/yuanzhenwei521/article/details/81737407?utm_source=copy
Docker入坑系列(一)
引用嘛,当然是来引用别人说的东西啦。
Docker 是一个开源项目,诞生于 2013 年初,它基于 Google 公司推出的 Go 语言实现。 项目后来加入了 Linux 基金会,遵从了 Apache 2.0 协议,项目代码在 GitHub 上进行维护。
PS:
- 由于小轩对Centos7命令不太熟,所以此次系统选择的Centos6.5。(其实是手里只有6.5和7的镜像啦,不想再下载啦。)
- 针对Centos6.x最小化安装之后的一些个人习惯,参见:Centos6.x最小化安装后的9件事。当然灵感来源于Ubuntu16.04安装后必备14件事-。-
记得不知道在哪里看过,Docker在Centos上有内核要求,从别家博客扒拉出来的一个要求是这样的:
- 必须是64位Centos。
- 建议内核在3.8以上。
既然首次入坑,就先按照先辈们的经验来吧:
查看系统位数
➜ ~ getconf LONG_BIT
64
嗯,64的。
查看内核版本
➜ ~ uname -r
2.6.32-754.3.5.el6.x86_64
➜ ~ uname -a
Linux docker.centos6.5 2.6.32-754.3.5.el6.x86_64 #1 SMP Tue Aug 14 20:46:41 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
嗯,内核版本2.6…….显然,内核版本不靠谱啊。那就先升级内核吧。
Centos6.5 内核升级
在Linux中,内核升级在我认知的世界中有两种方式:
- 内核源码编译
- rpm包安装
咳咳,咱们这次的主题是Docker不是Linux~,所以就使用rpm包安装吧。(其实昨天在阿里云上下载了3个小时的内核包都没下完。耐性不够啊-。-)
既然是rpm包安装那就简单多啦。
rpm安装linux内核
首先呢,以root用户输入
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
- 1
之后呢,输入
rpm -Uvh https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
- 1
然后咧,输入
yum -y --enablerepo=elrepo-kernel install kernel-lt
- 1
别打我~这里有。参见Get started~~
静静的等待软件包下载完毕,小轩这里就不上图了,直接copy吧。
➜ /opt yum -y --enablerepo=elrepo-kernel install kernel-lt
已加载插件:fastestmirror
设置安装进程
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* elrepo: ftp.utexas.edu
* elrepo-kernel: ftp.utexas.edu
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
elrepo | 2.9 kB 00:00
elrepo/primary_db | 694 kB 00:02
elrepo-kernel | 2.9 kB 00:00
elrepo-kernel/primary_db | 22 kB 00:00
解决依赖关系
--> 执行事务检查
---> Package kernel-lt.x86_64 0:4.4.147-1.el6.elrepo will be 安装
--> 完成依赖关系计算
依赖关系解决
========================================================================================
软件包 架构 版本 仓库 大小
========================================================================================
正在安装:
kernel-lt x86_64 4.4.147-1.el6.elrepo elrepo-kernel 39 M
事务概要
========================================================================================
Install 1 Package(s)
总下载量:39 M
Installed size: 178 M
下载软件包:
kernel-lt-4.4.147-1.el6.elrep 50% [=========- ] 67 kB/s | 20 MB 04:52 ETA
速度堪优啊。。。。。。。。。。。
Waiting…………..
我去,好坑啊-。-把*一关,下载完了。。。。。尴尬。走着,咱们继续。
总下载量:39 M
Installed size: 178 M
下载软件包:
http://ftp.utexas.edu/elrepo/kernel/el6/x86_64/RPMS/kernel-lt-4.4.147-1.el6.elrepo.x86_64.rpm: [Errno 12] Timeout on http://ftp.utexas.edu/elrepo/kernel/el6/x86_64/RPMS/kernel-lt-4.4.147-1.el6.elrepo.x86_64.rpm: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
尝试其他镜像。
http://muug.ca/mirror/elrepo/kernel/el6/x86_64/RPMS/kernel-lt-4.4.147-1.el6.elrepo.x86_64.rpm: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'muug.ca'"
尝试其他镜像。
kernel-lt-4.4.147-1.el6.elrepo.x86_64.rpm | 39 MB 00:41
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
Warning: RPMDB altered outside of yum.
正在安装 : kernel-lt-4.4.147-1.el6.elrepo.x86_64 1/1
Verifying : kernel-lt-4.4.147-1.el6.elrepo.x86_64 1/1
已安装:
kernel-lt.x86_64 0:4.4.147-1.el6.elrepo
完毕!
➜ /opt
好啦,之后呢,我们让系统以CentOS (4.4.147-1.el6.elrepo.x86_64)内核启动。
以root身份修改/etc/grub.conf文件,将default修改为CentOS (4.4.147-1.el6.elrepo.x86_64)的下标。
PS:
可以这样说吧-。-学名叫啥我也不知道,对于程序员来说,数组下标能更好理解???
经过Centos6.x最小化安装后的9件事这里的配置,应该是第10行。将第10行的default=1修改为default=0
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg_docker-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (4.4.147-1.el6.elrepo.x86_64)
root (hd0,0)
kernel /vmlinuz-4.4.147-1.el6.elrepo.x86_64 ro root=/dev/mapper/vg_docker-lv_root nomodeset rd_NO_LUKS rd_LVM_LV=vg_docker/lv_swap LANG=en_US.UTF-8 rd_LVM_LV=vg_docker/lv_root rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-4.4.147-1.el6.elrepo.x86_64.img
title CentOS (2.6.32-754.3.5.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-754.3.5.el6.x86_64 ro root=/dev/mapper/vg_docker-lv_root nomodeset rd_NO_LUKS rd_LVM_LV=vg_docker/lv_swap LANG=en_US.UTF-8 rd_LVM_LV=vg_docker/lv_root rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-754.3.5.el6.x86_64.img
title CentOS (2.6.32-431.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/vg_docker-lv_root nomodeset rd_NO_LUKS rd_LVM_LV=vg_docker/lv_swap LANG=en_US.UTF-8 rd_LVM_LV=vg_docker/lv_root rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-431.el6.x86_64.img
好了,最重要的一步!!!输入:init 6或者reboot让服务器重启~~~~
✘ [email protected] ~ ssh [email protected]
Last login: Thu Aug 16 10:29:43 2018 from 10.211.55.2
➜ ~ uname -r
4.4.147-1.el6.elrepo.x86_64
➜ ~
大功告成~~~我们的系统内核已经成功的从2.6.32-754.3.5.el6.x86_64升级到了4.4.147-1.el6.elrepo.x86_64~~那接下来就是Docker真正的入坑纪录了!
Let’s go!
彩蛋
提供一些查看linux系统版本号和系统位数的方法:
➜ ~ cat /etc/redhat-release
CentOS release 6.10 (Final)
➜ ~ cat /proc/version
Linux version 4.4.147-1.el6.elrepo.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) ) #1 SMP Thu Aug 9 10:58:02 EDT 2018
➜ ~ uname -a
Linux docker.centos6.5 4.4.147-1.el6.elrepo.x86_64 #1 SMP Thu Aug 9 10:58:02 EDT 2018 x86_64 x86_64 x86_64 GNU/Linux
➜ ~ uname -r
4.4.147-1.el6.elrepo.x86_64
➜ ~ cat /etc/issue
CentOS release 6.10 (Final)
Kernel \r on an \m
➜ ~ getconf LONG_BIT
64
➜ ~ file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
➜ ~
安装Docker
ok,原文地址在这里。
当然,我只是自己翻译了一下而已- -跟着做了一遍就安装好啦。
# Docker 是一个能够让应用自动化部署的基础软件框架。"容器"是封装好的,轻量级的便携式应用模块
# Docker is a container-based software framework for automating deployment of applications. “Containers” are encapsulated, lightweight, and portable application modules.
# 预检
# Pre-Flight Check
# 2014年6月 Docker官方正式发行v1.0.0版
# - As of June 2014 Docker has officially released v1.0.0.
# 这是如何安装Docker的使用说明
# - These instructions are intended for installing Docker.
# 我将在Liquid Web Core Managed Centos6.5服务器上安装Docker,并且是以root身份登陆的。
# - I’ll be working from a Liquid Web Core Managed CentOS 6.5 server, and I’ll be logged in as root.
# 添加EPEL资源库
# Add the EPEL Repository
# Docker 是EPEL扩展包的一部分,是RHEL发行的非标准的社区资源库。
# Docker is part of Extra Packages for Enterprise Linux (EPEL), which is a community repository of non-standard packages for the RHEL distribution.
### 首先,我们先安装EPEL资源库
### First, we’ll install the EPEL repository:
rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
### 然后,我们最好更新一下我们的包
### Then, as a matter of best practice, we’ll update our packages:
yum update -y
### 介绍 现在让我们通过docker-io包安装docker
### Installation
### Now let’s install Docker by installing the docker-io package:
yum -y install docker-io
### 等安装完成后,我们需要后台启动Docker服务
### Once the installation completes, we’ll need to start the Docker daemon:
service docker start
### 最后,我们可以配置Docker服务开机自启。当然也可以不配置
### And finally, and optionally, let’s configure Docker to start when the server boots:
chkconfig docker on
### 下载一个Docker容器,让我们开始使用Docker,下载centos的Docker镜像
### Download a Docker Container
### Let’s begin using Docker! Download the centos Docker image:
docker pull centos
### 运行一个Docker容器
### Run a Docker Container
### 现在,构建一个带有bash shell命令的基本centos容器,我们只需要运行一个命令:docker run。就会创建一个新的容器。
### -i:附带着标准输入输出用来交互
### -t:将分配一个tty,我们将使用标准的fedora容器
### Now, to setup a basic centos container with a bash shell, we just run one command. docker run will run a command in a new container, -i attaches stdin and stdout, -t allocates a tty, and we’re using the standard fedora container.
docker run -i -t centos /bin/bash
### 现在你正在一个centos Docker容器中使用bash shell
### That’s it! You’re now using a bash shell inside of a centos docker container.
### 如想退出或者离开,请保持按下Ctrl键不动并依次按下pq键。
### To disconnect, or detach, from the shell without exiting use the escape sequence Ctrl-p + Ctrl-q.
### 这里有许多已经可以用的社区容器,他们可以通过search来找到,例如找一个centos
### There are many community containers already available, which can be found through a search. In the command below I am searching for the keyword centos:
docker search centos
累死了-。-蹩脚英文总算看懂了。所以,来图。
当然还有程序员的Helloworld。