• 内网环境下让容器上网,并制作一个httpd容器


    1.下载基础镜像

    上一次,我们通过正向互联网代理在内网环境中,搭建了一个docker环境,具体环境如下:

    1) 内网docker服务器:192.168.123.1,操作系统为:redhat 7.9
    2) 代理服务器(可通外网):192.168.110.2,操作系统为:redhat 7.9
    
    • 1
    • 2

    我们在docker服务器上下载镜像进行测试:

    docker pull centos
    
    • 1

    2.运行容器

    docker run -itd -p 8080:80 --name wxtest_container --privileged centos /sbin/init
    
    • 1

    注:这里使用–privileged和/sbin/init参数启动容器,主要是为了方便在容器中安装软件,并通过systemctl命令启动软件服务

    3.登陆容器

    通过docker exec登陆容器

    docker exec -it wxtest_container /bin/bash
    
    • 1

    4.测试是否可以通外网

    curl https://www.baidu.com/
    
    • 1

    发现无法通外网

    5.更改配置,让容器登陆外网

    vi /etc/profile
    export http_proxy=http://192.168.110.2:9099
    export https_proxy=http://192.168.110.2:9099
    export no_proxy=localhost,127.0.0.1
    
    source /etc/profile
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    6.测试是否可以通外网

    curl https://www.baidu.com/
    
    • 1

    7.配置yum源

    由于在docker下没有安装wget工具,因此可以使用curl下载镜像源

    curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
    
    • 1

    8.安装Apache http服务

    yum install -y httpd
    
    • 1

    9.创建默认的访问界面index.html,启动httpd服务

    echo 'HelloDocker' >> /var/www/html/index.html
    
    systemctl start httpd
    systemctl enable httpd
    
    • 1
    • 2
    • 3
    • 4

    10.制作镜像

    在docker服务器上,制作镜像

    docker commit wx_tests_container Self_httpd
    
    • 1
  • 相关阅读:
    软考网络工程师路由器配置考点总结
    Chapter 11 EM算法
    PHP-字符串函数
    bit band
    DBT 项目建立
    Facebook的虚拟社交愿景:元宇宙时代的新起点
    Prometheus和grafana安装配置手册
    深入Go语言:进阶指南
    Pytorch - 使用torchsummary/torchsummaryX/torchinfo库打印模型结构、输出维度和参数信息
    2022年最火的十大测试工具,你掌握了几个
  • 原文地址:https://blog.csdn.net/wx370092877/article/details/134420571