windows用户手撸开发炼丹炉(WSL2中使用Docker基于Centos7.9+宝塔7.9配置的开发环境)

必看资料

第一个视频初步了解

https://www.bilibili.com/video/BV1s54y1n7Ev?share_source=copy_web

第二个视频学习Docker

https://www.bilibili.com/video/BV11L411g7U1?share_source=copy_web

图文资料https://docker.easydoc.net/doc/81170005/cCewZWoN/lTKfePfP

安装与环境配置https://blog.csdn.net/github_39577257/article/details/107180891

1.运行一个centos容器(版本:centos7.9.2009)

注意:如果说是把这个docker当作开发环境的话推荐使用 --net=host 的方式,省去很多麻烦

docker run -itd --name oldfriend-bt -p 80:80 -p 22:22 -p 21:21 -p 443:443 -p 8888:8888 -p 3306:3306 -p 6379:6379 -p 9500:9500 -p 7700-7720:7700-7720 -v /home/WorkSpace:/www/wwwroot --privileged centos:centos7.9.2009 /usr/sbin/init
docker run -itd -p 80:80 -p 8888:8888 -p 9500:9500 -p 3306:3306 -p 888:888 -v /home/WorkSpace:/www/wwwroot --privileged=true --name="oldfriend-bt" registry.cn-hangzhou.aliyuncs.com/oldfriend/oldfriend-bt /usr/sbin/init
docker run -itd --net=host -v /home/WorkSpace:/www/wwwroot --privileged=true --name="oldfriend-bt-host" registry.cn-hangzhou.aliyuncs.com/oldfriend/oldfriend-bt /usr/sbin/init

2.配置网络

首先需要检查是否存在**/etc/sysctl.conf文件,如果不存在就在创建一个,如果存在,则检查net.ipv4.ip_forward**项

还有一种方法:https://blog.csdn.net/qq_39774931/article/details/116517589

## 假设 sysctl.conf 文件不存在
vi /etc/sysctl.conf
## 在 sysctl.conf 中增加 net.ipv4.ip_forward = 1 , 表示允许进行路由转发
net.ipv4.ip_forward = 1
## 加载参数到内核
sysctl -p

## 重启网络
# service network restart

## 重启Docker
service docker restart

## 重启容器
# docker restart xxx

## 进入容器测试网络连接情况
docker exec -it xxx bin/bash  
ping www.baidu.com
# 如果上述做完还是不可以,就重启电脑,
# 重启之后还是不可以就重复上述操作在重启电脑

确认容器网路可用之后,就可以开始安装的工具。

安装zsh

# 不强制哈
yum install -y zsh
# 进入容器
docker exec -it xxx bin/zsh  
## 补充两个常用的工具包,包括了 ip vim 工具
yum install -y git iproute vim openssh openssh-clients.aarch64 openssh-server.aarch64 epel-release systemd NetworkManager
# 各个网站推荐的工具,自行看着选
# 安装必要工具
# yum install -y yum-utils device-mapper-persistent-data lvm2
# 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

#安装基础指令
yum -y install sudo 
yum -y install initscripts
# 网络工具
##如果就习惯用 ifconfig,则需要通过下面命令安装工具包 net-tools,命令如下:
yum install net-tools

3.安装宝塔(7.9)

注:如果yum失败,请查看:

https://www.cnblogs.com/houss/p/11286392.html

#安装宝塔
## 找个目录放 home 或者 www 都可以
cd /home && mkdir oldf-bt && cd oldf-bt
## 在oldf-bt目录运行Centos安装脚本
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh ed8484bec

#宝塔工具
bt

安全配置: https://blog.csdn.net/qq_44402184/article/details/123718815

4.修改宝塔

# 修改docker面版命令行
cd /www/server/panel
# 编辑文件
vim tools.py
# 修改宝塔后台终端面版命令行
cd /www/server/panel/class
# 编辑文件
vim tools.py

#修改login页面与宝塔后台标题

5.使用宝塔

现在就可以使用宝塔了

FAQ

push到阿里云

1.登录阿里云Docker Registry

docker login --username=oldfriend registry.cn-hangzhou.aliyuncs.com

2.将镜像推送到Registry

# 新建一个tag,名字必须跟你注册账号一样
docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/oldfriend/xxx:[镜像版本号]
# 推上去
docker push registry.cn-hangzhou.aliyuncs.com/oldfriend/xxx:[镜像版本号]

3.从Registry中拉取镜像

docker pull registry.cn-hangzhou.aliyuncs.com/oldfriend/xxx:[镜像版本号]

将容器做成镜像

docker commit 当前运行的容器名 新镜像名:版本号  

美化终端

https://zhuanlan.zhihu.com/p/342667468

source ~/.zshrc错误问题:https://www.cnblogs.com/hongdada/p/14043871.html

git下载插件的时候换行符自动转换造成的
$ git config --list |grep autocrlf
core.autocrlf=true

$ git config core.autocrlf false
$ git config --global core.autocrlf false

开机自启动宝塔面板

# zsh终端
# 在此文件中添加脚本 bt
$ source ~/.zshrc

docker服务无法启动

报错:Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

检查/etc/docker/daemon.json文件,保证是正确的json格式

如果还是不行,请替换成下面的配置
{
        "registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://mirror.ccs.tencentyun.com","https://oldfriend.mirror.aliyuncs.com"]
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值