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

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]端口才能访问面板

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

http://www.xdnf.cn/news/4400.html

相关文章:

  • 【Java项目脚手架系列】第三篇:Spring MVC基础项目脚手架
  • blender云渲染指南2025版
  • 【Rust模块管理】Rust包、crate与模块管理
  • WSL 的 Ubuntu 子系统中启用图形化界面
  • 处理PostgreSQL数据库事务死锁过程
  • 极狐Gitlab 如何创建并使用子群组?
  • 5月7号.
  • ESP32- 开发笔记- 软件开发 6 蓝牙协议栈 1
  • console-chat-gpt开源程序是用于 AI Chat API 的 Python CLI
  • 屏幕炫光也能轻松应对,远程控制电脑可以避免裂痕碍眼
  • 白杨SEO:如何查看百度、抖音、微信、微博、小红书、知乎、B站、视频号、快手等7天内最热门话题及流量关键词有哪些?使用方法和免费工具推荐以及注意事项【干货】
  • NX二次开发——BlockUI 弹出另一个BlockUI对话框
  • 深入了解linux系统—— 进程控制
  • PPT 制作难题迎刃而解,影刀 RPA 开启自动化创作时代
  • Kotlin 中实现单例模式的几种常见模式
  • 用R语言+随机森林玩转遥感空间预测-基于R语言机器学习遥感数据处理与模型空间预测技术及实际项目案例分析
  • 全局网络:重构数字时代的连接范式
  • 【Hive入门】Hive增量数据导入:基于Sqoop的关系型数据库同步方案深度解析
  • 汽车服务小程序功能点开发
  • 康养休闲旅游住宿服务实训室:构建产教融合新标杆
  • JVM的双亲委派模型
  • 基于RK3568多功能车载定位导航智能信息终端
  • 【IP101】图像分割技术全解析:从传统算法到深度学习的进阶之路
  • 【图书管理系统】详细讲解用户登录:后端代码实现及讲解、前端代码讲解
  • vue2开发者sass预处理注意
  • 关于STM32 SPI收发数据异常
  • 日常开发中,iOS 性能调优我们怎么做?
  • ISCC 2025练武题 WP部分
  • DELL R770 服务器,更换OCP模块!
  • (九)PMSM驱动控制学习---分流电阻采样及重构