1.安装docker
#查看linux内核
uname -r
#安装软件包
yum install -y yum-utils
#直接参考网上教程
参考:centos7安装Docker详细步骤(无坑版教程)-腾讯云开发者社区-腾讯云 (tencent.com)
2 用docker部署mysql
#拉取镜像
[root@hdp01 ~]# docker pull mysql:5.7.29
5.7.29: Pulling from library/mysql
54fec2fa59d0: Downloading [==================================================>] 27.1MB/27.1MB
....
Digest: sha256:95b4bc7c1b111906fdb7a39cd990dd99f21c594722735d059769b80312eb57a7
Status: Downloaded newer image for mysql:5.7.29
docker.io/library/mysql:5.7.29
#创建容器
[root@hdp01 ~]# docker run -id --name=outside_mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.29
688cafdf8e8710f48589b65d3619b58ff9c50f481f4e00f603c649c02a2b550a
#查看正在运行的容器并进入到mysql容器
[root@hdp01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
688cafdf8e87 mysql:5.7.29 "docker-entrypoint.s…" 26 seconds ago Up 24 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 330 60/tcp outside_mysql
#进入mysql容器
[root@hdp01 ~]# docker exec -it outside_mysql /bin/bash
root@688cafdf8e87:/# ls
bin boot dev docker-entrypoint-initdb.d entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
#启动mysql
root@688cafdf8e87:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
3. 安装docker-compose
[root@hdp01 ~]# sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 162 100 162 0 0 174 0 --:--:-- --:--:-- --:--:-- 174
[root@hdp01 ~]# sudo chmod +x /usr/local/bin/docker-compose
[root@hdp01 ~]# ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
#查看版本信息
[root@hdp01 ~]# docker compose version
Docker Compose version v2.21.0
4. 安装Harbor
步骤一:将harbor-offline离线包放到虚拟机指定目录下并解压
编辑
步骤二:配置harbor.yml文件
编辑
步骤三:安装并启动Harbor
(注意:docker compose version)
[root@hdp01 harbor]# ./install.sh
[Step 0]: checking if docker is installed ...
Note: docker version: 24.0.6
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 2.21.0
[Step 2]: loading Harbor images ...
Loaded image: goharbor/notary-signer-photon:v0.6.1-v1.10.0
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /opt/tools/habor/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Clearing the configuration file: /config/log/logrotate.conf
[Step 5]: starting Harbor ...
[+] Running 10/10
✔ Network harbor_harbor Created 0.6s
✔ Container harbor-log Started 0.1s
✔ Container redis Started 0.2s
✔ Container registryctl Started 0.2s
✔ Container harbor-db Started 0.2s
✔ Container registry Started 0.2s
✔ Container harbor-portal Started 0.2s
✔ Container harbor-core Started 0.0s
✔ Container harbor-jobservice Started 0.1s
✔ Container nginx Started 0.1s
✔ ----Harbor has been installed and started successfully.----
出现stp4报错:安装Docker harbor报错:ERROR:root:Error: The protocol is https but attribute ssl_cert is not set-CSDN博客
出现step5报错:修改install.sh文件
编辑
步骤4:登录Harbor(admin | 123456)
编辑
5.配置、使用Harbor
#查看当前镜像
[root@hdp01 harbor]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 1.18.0 b2b1ac2c289c 15 hours ago 576MB
nginx latest 605c77e624dd 2 years a
#任务:将nginx:1.18.0上传到Harbor仓库
#修改/etc/docker/daemon.json文件,修改内容如下
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://fsp2sfpr.mirror.aliyuncs.com/"
],
"insecure-registries":["192.168.33.133"]
}
#登录harbor
[root@hdp01 harbor]# docker login -u admin -p 123456 192.168.33.133
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
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@hdp01 harbor]# docker tag nginx:1.18.0 192.168.33.133/mymarket/nginx:1.18.0
#上传镜像
[root@hdp01 harbor]# docker push 192.168.33.133/mymarket/nginx:1.18.0
The push refers to repository [192.168.33.133/mymarket/nginx]
b32e174539b7: Pushed
52d3c4a730cc: Pushed
b04d91fa8645: Pushed
5f70bf18a086: Pushed
f85dd509c465: Pushed
faefd4f41681: Pushed
174f56854903: Pushed
1.18.0: digest: sha256:bd88a49606ef0084bf590afa30b35fbdd6b0789c11bb2180d6dfa573353db02a size: 1784
总结:
本节是关于docker安装与配置以及Harbor使用的一些理论知识和操作演示,在docker部署django项目前需要各位了解与亲自实操,下一节我会分享如何使用docker+nginx+uwsgi去部署django 项目,如果你都是一步一步按照我的步骤来,你会学到很多,欢迎各位靓仔,大佬关注加点赞,感谢支持!