1、安装平台
Linux虚拟机:VirtualBox上安装的CentOS7
注意:CentOS7的内核要在3.10以上才能安装docker,查看内核命令:
uname -r
若不满足要求,可更新内核,但该步耗时较长,谨慎使用,更新命令如下:
yum update
2、安装过程
- ① 安装需要的软件包:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- ② 设置yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- ③ 查看仓库中docker版本
yum list docker-ce --showduplicates | sort -r
- ④ 安装docker
sudo yum install docker-ce
为什么要如此复杂的去安装docker,是因为使用简单命令yum install dacker
进行安装时,往往只安装了docker的客户端,没有安装docker的服务器端,所以使用以上流程进行安装。
- ⑤ 安装后查看docker版本
root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:27:04 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:25:42 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
安装之后,查看版本情况如上。
3、docker使用
- ① 启动docker并设置开机启动
sudo systemctl start docker
sudo systemctl enable docker
- ② 在docker启动后,执行
docker search mysql
之前需要先进行以下配置:
(1)改变daemon.json文件,具体操作如下:
//命令行中输入该命令,进入daemon.json文件进行修改
[root@localhost ~]# vi /etc/docker/daemon.json
//进入daemon.json文件后,为空:直接将以下内容复制进去
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
//复制完成,按Esc,再输入 :wq 保存并退出
(2)改变服务器DNS网络配置
//输入该命令,进入resolv.conf的配置文件
vi /etc/resolv.conf
进入resolv.conf的配置文件后,将其中内容全部清除,复制以下内容:
nameserver 8.8.8.8
nameserver 8.8.8.4
- ③ 输入
docker search mysql
命令,查看mysql版本,结果如下:
NAME DESCRIPTION
STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relatio
n… 9265 [OK]
mariadb MariaDB is a community-developed fork of My
S… 3305 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Creat
e… 681 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server
71
mysql/mysql-cluster Experimental MySQL Cluster Docker images. C
r… 66
centurylink/mysql Image containing mysql. Optimized to be lin
k… 61 [OK]
deitch/mysql-backup REPLACED! Please use http://hub.docker.com/
r… 41 [OK]
bitnami/mysql Bitnami MySQL Docker Image
36 [OK]
tutum/mysql Base docker image to run a MySQL database s
e… 34
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backu
27 [OK]
linuxserver/mysql A Mysql container, brought to you by LinuxS
e… 24
centos/mysql-56-centos7 MySQL 5.6 SQL database server
19
circleci/mysql MySQL is a widely used, open-source relatio
n… 19
mysql/mysql-router MySQL Router provides transparent routing b
e… 14
arey/mysql-client Run a MySQL client from a docker container
13 [OK]
databack/mysql-backup Back up mysql databases to... anywhere!
13
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 imag
e… 6
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron ta
s… 5 [OK]
genschsa/mysql-employees MySQL Employee Sample Database
5 [OK]
devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offic
i… 2
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL
2 [OK]
jelastic/mysql An image of the MySQL database server maint
a… 1
monasca/mysql-init A minimal decoupled init container for mysq
l 0
widdpim/mysql-client Dockerized MySQL Client (5.7) including Cur
l… 0 [OK]
④ 输入docker pull mysql
命令,下载mysql最新版本,结果如下:
Using default tag: latest
68ced04f60ab: Pull complete
f9748e016a5c: Pull complete
da54b038fed1: Pull complete
6895ec5eb2c0: Pull complete
111ba0647b87: Pull complete
c1dce60f2f1a: Pull complete
702ec598d0af: Pull complete
4aba2fcbe869: Pull complete
b26bbbd533e6: Downloading 33.83MB/113MB
7bd100a66c55: Download complete
74149336419a: Download complete
145ea1f01648: Download complete
到此,docker安装、配置及其基本使用操作完成。