当前位置: 首页 > news >正文

docker创建一个centOS容器安装软件(以宝塔为例)的详细步骤

备忘:后续偶尔忘记了docker虚拟机与宿主机的端口映射关系,来这里查看即可:

docker run -d \
--name baota \
--privileged=true \
-p 8888:8888 \
-p 8880:80 \
-p 8443:443 \
-p 8820:20 \
-p 8821:21 \
-v /home/www:/www/wwwroot \
centos:7 /sbin/init

1.拉取系统镜像 推荐使用CentOS

docker pull centos:7 

2.启动容器

说明:建议按下面的执行 防止docker容器与宿主冲突端口
docker run -d \--name baota \--privileged=true \-p 8888:8888 \    # 面板端口-p 80:80 \        # HTTP-p 443:443 \      # HTTPS-p 20:20 \        # FTP-p 21:21 \        # FTP-v /home/www:/www/wwwroot \  # 挂载网站目录centos:7 /sbin/init建议执行这里
docker run -d \
--name baota \
--privileged=true \
-p 8888:8888 \
-p 8880:80 \
-p 8443:443 \
-p 8820:20 \
-p 8821:21 \
-v /home/www:/www/wwwroot \
centos:7 /sbin/init

注意:

  • --privileged=true 赋予容器root权限8
  • 端口映射需包含宝塔默认端口(8888)及常用服务端口

3.‌进入容器

docker exec -it baota /bin/bash

‌4.安装依赖工具

yum install -y wget || apt-get install -y wget

如果这一步执行失败:

Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"One of the configured repositories failed (Unknown),and yum doesn't have enough cached data to continue. At this point the onlysafe thing yum can do is fail. There are a few ways to work "fix" this:1. Contact the upstream for the repository and get them to fix the problem.2. Reconfigure the baseurl/etc. for the repository, to point to a workingupstream. This is most often useful if you are using a newerdistribution release than is supported by the repository (and thepackages for the previous distribution release still work).3. Run the command with the repository temporarily disabledyum --disablerepo=<repoid> ...4. Disable the repository permanently, so yum won't use it by default. Yumwill then just ignore the repository until you permanently enable itagain or use --enablerepo for temporary usage:yum-config-manager --disable <repoid>orsubscription-manager repos --disable=<repoid>5. Configure the failing repository to be skipped, if it is unavailable.Note that yum will try to contact the repo. when it runs most commands,so will have to try and fail each time (and thus. yum will be be muchslower). If it is a very temporary problem though, this is often a nicecompromise:yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=trueCannot find a valid baseurl for repo: base/7/x86_64
bash: apt-get: command not found

解决方案:

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back
sudo tee /etc/yum.repos.d/CentOS-Base.repo <<-'EOF'
[base]
name=CentOS-$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7[updates]
name=CentOS-$releasever - Updates
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7EOF

5.安装宝塔

建议去宝塔https://www.bt.cn/new/download.html官网看最新执行脚本:

if [ -f /usr/bin/curl ];then curl -sSO https://download.bt.cn/install/install_panel.sh;else wget -O install_panel.sh https://download.bt.cn/install/install_panel.sh;fi;bash install_panel.sh ed8484bec
Complete!
success
install_panel.sh: line 1426: ip: command not found
==================================================================
Congratulations! Installed successfully!
=============注意:首次打开面板浏览器将提示不安全=================请选择以下其中一种方式解决不安全提醒1、下载证书,地址:https://dg2.bt.cn/ssl/baota_root.pfx,双击安装,密码【www.bt.cn】2、点击【高级】-【继续访问】或【接受风险并继续】访问教程:https://www.bt.cn/bbs/thread-117246-1-1.htmlmac用户请下载使用此证书:https://dg2.bt.cn/ssl/mac.crt========================面板账户登录信息==========================【云服务器】请在安全组放行 26917 端口外网ipv4面板地址: http://125.38.78.51:26917/aa3b4cbe内网面板地址:     http://:26917/aa3b4cbeusername: lhk5vaygpassword: df6f2add浏览器访问以下链接,添加宝塔客服https://www.bt.cn/new/wechat_customer
==================================================================
Time consumed: 7 Minute!

6.端口映射

安装完发现面板端口是26917,我们对docker容器的预判是给它8888.盘它

容器中继续:

bt
8
8888
[root@92c97e20812a yum.repos.d]# bt
==================================宝塔面板命令行====================================
(1) 重启面板服务                  (8) 改面板端口                                   |
(2) 停止面板服务                  (9) 清除面板缓存                                 |
(3) 启动面板服务                  (10) 清除登录限制                                |
(4) 重载面板服务                  (11) 设置是否开启IP + User-Agent验证             |
(5) 修改面板密码                  (12) 取消域名绑定限制                            |
(6) 修改面板用户名                (13) 取消IP访问限制                              |
(7) 强制修改MySQL密码             (14) 查看面板默认信息                            |
(22) 显示面板错误日志             (15) 清理系统垃圾                                |
(23) 关闭BasicAuth认证            (16) 修复面板(检查错误并更新面板文件到最新版)    |
(24) 关闭动态口令认证             (17) 设置日志切割是否压缩                        |
(25) 设置是否保存文件历史副本     (18) 设置是否自动备份面板                        |
(26) 关闭面板ssl                  (19) 关闭面板登录地区限制                        |
(28) 修改面板安全入口             (29) 取消访问设备验证                            |
(30) 取消访问UA验证               (32) 开启/关闭【80、443】端口访问面板            |
(0) 取消                                                                           |
====================================================================================
请输入命令编号:8
===============================================
正在执行(8)...
===============================================
请输入新的面板端口:8888
success
success
Reload Bt-Panel..	done
|-已将面板端口修改为:8888
|-若您的服务器提供商是[阿里云][腾讯云][华为云]或其它开启了[安全组]的服务器,请在安全组放行[8888]端口才能访问面板

在这里插入图片描述
大功告成!

相关文章:

  • CentOS 7 安装OpenJDK 17 JRE
  • 空间数据分析新趋势:AI 与 ArcGIS Pro 的协同创新
  • 使用 Gradio + Qwen3 + vLLM 部署 Text2SQL 多表查询系统
  • MySQL 8.0 OCP(1Z0-908)英文题库(1-10)
  • Linux NVIDIA 显卡驱动安装指南(适用于 RHEL/CentOS)
  • 检测内存条好坏有工具,推荐几款内存检测工具
  • 从明文裸奔到密钥长城:HTTPS加密全链路攻防与CA信任锚点构建
  • 直播数据大屏是什么?企业应如何构建直播数据大屏?
  • Linux:认识基础IO
  • TikTok 矩阵运营新手实操保姆级教程 2.0 版本
  • CentOS 7.9 安装详解:手动分区完全指南
  • C++排序算法(一)
  • 统信服务器系统reposync命令详解
  • CentOS算法部署
  • 【数据结构】手撕二叉搜索树
  • 【Linux系列】如何区分 SSD 和机械硬盘
  • Ubuntu 使用dotfiles个性化配置模板
  • 鸿蒙开发——4.ArkTS快速入门指南
  • 一种扫描雷达超分辨成像检测一体化方法——论文阅读
  • python23-函数返回值和参数处理,变量作用域
  • 美国再工业化进程需要中国的产业支持
  • 卢正已任上海市司法局党委委员、副局长
  • 肖峰读《从塞北到西域》︱拉铁摩尔的骆驼
  • 工程院院士葛世荣获聘任为江西理工大学校长
  • 烈士沈绍藩遗孤、革命家帅孟奇养女舒炜逝世,享年96岁
  • 保证断电、碰撞等事故中车门系统能够开启!汽车车门把手将迎来强制性国家标准