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

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

bash 复制代码
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

bash 复制代码
docker pull centos:7 

2.启动容器

bash 复制代码
说明:建议按下面的执行 防止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.‌进入容器

bash 复制代码
docker exec -it baota /bin/bash

‌4.安装依赖工具

log 复制代码
yum install -y wget || apt-get install -y wget

如果这一步执行失败:

log 复制代码
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

解决方案:

bash 复制代码
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back
bash 复制代码
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官网看最新执行脚本:

bash 复制代码
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
log 复制代码
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.盘它

容器中继续:

bash 复制代码
bt
8
8888
bash 复制代码
[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]端口才能访问面板

大功告成!

相关推荐
徐先生 @_@|||几秒前
YARN、YARN/K8s混合模式与Kubernetes分析对比
docker·云原生·容器·kubernetes
遇见火星1 分钟前
CI/CD实战:从手动部署到自动化流水线
运维·ci/cd·自动化
Snower_20229 分钟前
CentOS 7 搭建 SVN 服务器(精简版教程)
linux·运维·服务器·svn·centos
这周也會开心10 分钟前
Docker Compose容器化部署
运维·docker·容器
UP_Continue23 分钟前
Linux--OS和认识进程
linux·运维·服务器
IT摆渡者25 分钟前
Rocky Linux 10.1中找不到传统的 /etc/sysconfig/network-scripts 目录是正常现象。
linux·运维·服务器·网络·经验分享
无小道32 分钟前
基于epoll的单进程Reactor服务器
运维·服务器·c++·网络编程·reactor·epoll
Justin_1935 分钟前
K8s常见问题(5)
云原生·容器·kubernetes
Thomas214337 分钟前
jupyterhub on k8s jupyter总是无响应
jupyter·容器·kubernetes
qq_3957161738 分钟前
服务器加硬盘应该用 RAID 几好?
运维·服务器