先给大家来点干货
docker 是什么?
docker 是使用go语言开发的,开源应用容器引擎!他的主要作用就是来运行容器的!
我们可以把一些应用或者环境打包在一个容器中,然后在安装了docker的服务器上都可以直接运行这个容器!然后直接访问!
例如
我们把电商网站这个php应用直接打包在一个容器中!
只要我们的服务器上安装了docker就可以直接运行这个容器,
然后就可以直接访问到这个容器里面的电商网站! 而我们运行容器我们只需要一个命令!这让我们可以快速的部署一些
复杂的应用或者环境!镜像:
作用是用来创建容器的!
wordpress wordpress的镜像---》创建容器
zabbix zabbix镜像----》zabbix容器容器:
可以迁移、轻量级
以镜像的形式迁移的!仓库:
存放镜像的!
私有仓库!
harbor 私有镜像,定制的镜像!
直接上硬货
1.首先安装docker源 192.168.72.150
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
检查源文件是否创建成功
ls /etc/yum.repos.d/docker-ce.repo
2.安装docker
yum -y install docker-ce
3.启动docker 并将docker设置为开机自启
systemctl start docker
systemctl enable docker
4.配置镜像加速
默认情况下,我们docker会去hub.docker.com下载镜像,速度会非常慢
所以要做一下docker加速!我们这里使用的是阿里云的加速!
将群里的daemon.json配置文件,上传到/etc/docker/目录下,然后重启docker就完成加速了
记得重启一下啊!!!!
5.测试docker
docker run hello-world 这样我docker就下载好了
这个是docker下载镜像厂库,需要什么可以直接下载
https://hub.docker.com/search?q=nginx&type=image
docker常用命令
1.下载镜像:
docker pull nginx
docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
b4d181a07f80: Pull complete
edb81c9bc1f5: Pull complete
b21fed559b9f: Pull complete
03e6a2452751: Pull complete
b82f7f888feb: Pull complete
5430e98eba64: Pull complete
Digest: sha256:47ae43cdfc7064d28800bc42e79a429540c7c80168e8c8952778c0d5af1c09db
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 4f380adfc10f 8 days ago 133MB
hello-world latest d1165f221234 3 months ago 13.3kB
在开一个服务器 192.168.72.151 安装harbor需要docker-ce和docker-compose
ok 这样可以看到我们下载下来了,我们要上传到镜像私有厂库Harbor
离线安装:
1.解压离线安装包
# tar zxf harbor-offline-installer-v1.9.4.tgz
# mv harbor /usr/local/
# cd /usr/local/harbor
[root@localhost ~]# tar -xvf harbor-offline-installer-v1.9.4.tgz
harbor/harbor.v1.9.4.tar.gz
harbor/prepare
harbor/LICENSE
harbor/install.sh
harbor/harbor.yml
[root@localhost ~]# ls
anaconda-ks.cfg harbor harbor-offline-installer-v1.9.4.tgz
[root@localhost ~]# mv harbor /usr/local/
[root@localhost ~]# cd /usr/local/harbor/
[root@localhost harbor]# ls
harbor.v1.9.4.tar.gz harbor.yml install.sh LICENSE prepare
[root@localhost harbor]#
更改配置文件
# vim harbor.yml
hostname: 192.168.189.151 \\访问的IP地址
http:
port: 80 \\端口
harbor_admin_password: admin Harbor12345 \\管理员admin的密码
执行安装脚本,耐心等待,执行完毕就安装成功,直接访问即可
# sh install.sh
这里需要我们安装上docker-compose
[root@localhost harbor]# sh install.sh
[Step 0]: checking installation environment ...
Note: docker version: 20.10.7
✖ Need to install docker-compose(1.18.0+) by yourself first and run this script again.
我们先介绍一下 docker-compose
--------------------------------------------
多容器管理!单机容器编排工具
管理的单位是服务,一个服务下至少一个容器
读取文件来实现容器的创建、启动......
读取的文件我们叫做模板文件!
默认情况下:
容器和容器之间可以实现服务名互相解析!
1.命令: docker-compose
docker-compose下载: https://github.com/docker/compose/releases
yum instaall wget
1.安装 wget https://github.com/docker/compose/releases
上传 docker-compose-Linux-x86_64
# mv docker-compose-Linux-x86_64 /usr/local/sbin/docker-compose
# chmod +x /usr/local/sbin/docker-compose
# docker-compose -v
docker-compose version 1.26.2, build eefe0d31
[root@localhost harbor]# mv docker-compose-Linux-x86_64 /usr/local/sbin/docker-compose
[root@localhost harbor]# cd /usr/local/sbin/
[root@localhost sbin]# ls
docker-compose
[root@localhost sbin]# chmod +x /usr/local/sbin/docker-compose
[root@localhost sbin]# docker-compose -v
docker-compose version 1.26.2, build eefe0d31
[root@localhost sbin]#
注意:安装docker-compose的主机一定要安装docker-ce,因为docker-compose只是一个编排容器的工具,底层的容器需要使用docker-ce来实现!、
docker-compose每一条命令执行时,都需要读取对应的模板文件!然后才能找到对应容器进行操作,如果没有指定文件,是会报错的! docker-compose编排后面在出一份文档,今天先学基础
在重新启动Harbor脚本
[root@localhost sbin]# cd /usr/local/harbor/
[root@localhost harbor]# ls
harbor.v1.9.4.tar.gz harbor.yml install.sh LICENSE prepare releases
[root@localhost harbor]# sh install.sh
这样就好了
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating redis ... done
Creating registryctl ... done
Creating registry ... done
Creating harbor-portal ... done
Creating harbor-db ... done
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----
Now you should be able to visit the admin portal at http://192.168.72.150.
For more details, please visit https://github.com/goharbor/harbor .
1.修改配置文件
# vim /etc/docker/daemon.json{
"registry-mirrors": ["https://q3u0qv3z.mirror.aliyuncs.com"],
"insecure-registries":["192.168.72.151"]
}
重启docker
# systemctl daemon-reload
# systemctl restart docker
[root@localhost ~]# docker login 192.168.72.151
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@localhost ~]# ls
关闭防火墙可以直接 http://192.168.72.151/harbor/projects
3.推送镜像到私有仓库
docker tag nginx:latest 192.168.72.151/docker/nginx:3.0· 把nginx镜像相当于复制出来重命名一下
docker push 192.168.72.151/docker/nginx:3.0
4.从仓库拉取镜像
# docker pull 192.168.72.151/docker/nginx:3.0