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

发布于:2025-05-08 ⋅ 阅读:(22) ⋅ 点赞:(0)

备忘:后续偶尔忘记了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 only
 safe 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 working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-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 much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot 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-7

EOF

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.html
 mac用户请下载使用此证书:https://dg2.bt.cn/ssl/mac.crt

========================面板账户登录信息==========================

 【云服务器】请在安全组放行 26917 端口
 外网ipv4面板地址: http://125.38.78.51:26917/aa3b4cbe
 内网面板地址:     http://:26917/aa3b4cbe
 username: lhk5vayg
 password: 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]端口才能访问面板

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


网站公告

今日签到

点亮在社区的每一天
去签到