1:docker三大核心概念

镜像Docker镜像类似于虚拟机镜像,可以将它理解为一个只读的模板。
容器Docker容器类似于一个轻量级的沙箱,Docker利用容器来运行和隔离应用。
容器是从镜像创建的应用运行实例。它可以启动、开始、停止、删除,而这些容器都是彼此相互隔离、互不可见的。
仓库Docker仓库类似于代码仓库,是Docker集中存放镜像文件的场所

区分:注册服务器和仓库

02docker核心概念-LMLPHP

2:ubuntu下安装docker

安装docker前关闭selinux

手动添加软件源安装:

1:ubuntu@ubuntu:~$ uname -a    #内核版本至少3.10才支持docker
Linux ubuntu 5.3.0-19-generic #20-Ubuntu SMP Fri Oct 18 09:04:39 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux 2.安装如下两个软件包---让docker使用aufs存储
ubuntu@ubuntu:~$ sudo apt-get update
ubuntu@ubuntu:~$ sudo apt upgrade
ubuntu@ubuntu:~$ sudo apt install --reinstall linux-image-generic #重新升级到最新内核
ubuntu@ubuntu:~$ sudo apt install linux-modules-extra-$(uname -r) linux-image-extra-virtual #linux-image-generic应该已经安装了相关的linux-image-extra包,但名称已更改为linux-modules-extra 以上操作解决报错:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-image-extra-5.3.0-19-generic
E: Couldn't find any package by glob 'linux-image-extra-5.3.0-19-generic'
E: Couldn't find any package by regex 'linux-image-extra-5.3.0-19-generic' 3:添加镜像源
-首先需要安装apt-transport-https等软件包
ubuntu@ubuntu:~$ sudo apt-get update
ubuntu@ubuntu:~$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common -添加源的gpg密钥
ubuntu@ubuntu:~$ curl -fsSL http://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
OK -添加成功后
ubuntu@ubuntu:~$ sudo apt-get update -开始安装docker
ubuntu@ubuntu:~$ sudo apt-get install docker-ce
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source E: Package 'docker-ce' has no installation candidate 报错解决:
手动加入源
ubuntu@ubuntu:~$ cd /etc/apt/sources.list.d #进入到这个目录
ubuntu@ubuntu:/etc/apt/sources.list.d$ sudo vi docker.list #添加如下源
deb https://download.docker.com/linux/ubuntu zesty edge ubuntu@ubuntu:/etc/apt/sources.list.d$ sudo apt update #更新源 ubuntu@ubuntu:~$ sudo apt install docker-ce # ----开始安装 安装完成后检查:
ubuntu@ubuntu:~$ docker version --检查是否安装成功 ###配置docker服务
1.ubuntu@ubuntu:~$ sudo usermod -aG docker $USER #避免每次切换到sudo身份 2.Docker服务的默认配置文件为/etc/default/docker,可以通过修改其中的DOCKER_OPTS来修改服务启动的参数,例如让 Docker服务开启网络2375端口的监听:
DOCKER_OPTS="$DOCKER_OPTS -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
###docker开启远程tcp监听端口 3.ubuntu@ubuntu:~$ sudo service docker restart 重启服务

官方提供的脚本安装:

sudo curl -sSL https://get.docker.com/ | sh

3:redhat7安装docker

关闭selinux

[root@registry ~]# getenforce
Enforcing
[root@registry ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
reboot
1:更新
[root@localhost ~]# yum install update
2:支持devicemapper存储类型
[root@localhost ~]# sudo yum install -y yum-utils device-mapper-persistent-data
3:添加docker稳定的yum软件源
[root@localhost ~]# sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
4:更新yum软件源并安装
[root@localhost ~]# sudo yum update
5:安装
[root@localhost ~]#yum install install -y docker-ce
报错,有软件冲突
Error: initscripts conflicts with redhat-release-server-7.0-1.el7.x86_64
解决办法:
[root@localhost ~]# rpm -e redhat-release-server-7.0-1.el7.x86_64 --nodeps 再重新安装
[root@localhost ~]#yum install install -y docker-ce 安装完成后:
Docs: https://docs.docker.com
[root@localhost ~]# docker version
Client:
Version: 18.06.3-ce
API version: 1.38
Go version: go1.10.3
Git commit: d7080c1
Built: Wed Feb 20 02:26:51 2019
OS/Arch: linux/amd64
Experimental: false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[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.
有一个异常,只启动了client,server没有起来。 [root@localhost ~]# journalctl -xe |grep mkfs
Nov 13 18:10:14 localhost.localdomain dockerd[2567]: time="2019-11-13T18:10:14.159056463-05:00" level=info msg="Creating filesystem xfs on device docker-253:0-100841185-base, mkfs args: [-m crc=0,finobt=0 /dev/mapper/docker-253:0-100841185-base]" storage-driver=devicemapper
Nov 13 18:10:14 localhost.localdomain dockerd[2616]: time="2019-11-13T18:10:14.646244369-05:00" level=info msg="Creating filesystem xfs on device docker-253:0-100841185-base, mkfs args: [-m crc=0,finobt=0 /dev/mapper/docker-253:0-100841185-base]" storage-driver=devicemapper
Nov 13 18:10:15 localhost.localdomain dockerd[2644]: time="2019-11-13T18:10:15.165383379-05:00" level=info msg="Creating filesystem xfs on device docker-253:0-100841185-base, mkfs args: [-m crc=0,finobt=0 /dev/mapper/docker-253:0-100841185-base]" storage-driver=devicemapper
Nov 13 18:15:30 localhost.localdomain dockerd[2692]: time="2019-11-13T18:15:30.268616422-05:00" level=info msg="Creating filesystem xfs on device docker-253:0-100841185-base, mkfs args: [-m crc=0,finobt=0 /dev/mapper/docker-253:0-100841185-base]" storage-driver=devicemapper 找到根本原因是:
mkfs.xfs版本太低,遂更新:
[root@localhost ~]# yum update xfsprogs #更新软件版本
[root@localhost ~]# systemctl start docker.service #重启docker服务
[root@localhost ~]# systemctl enable docker.service #配置开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@localhost ~]# docker version
Client:
Version: 18.06.3-ce
API version: 1.38
Go version: go1.10.3
Git commit: d7080c1
Built: Wed Feb 20 02:26:51 2019
OS/Arch: linux/amd64
Experimental: false Server:
Engine:
Version: 18.06.3-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: d7080c1
Built: Wed Feb 20 02:28:17 2019
OS/Arch: linux/amd64
Experimental: false
05-11 20:18