Docker-构建基础镜像

基于服务器操作系统,构建docker镜像。

1.卸载防火墙、清理缓存

复制代码
找一台linux系统的机器,将此机器的系统构建为镜像
yum remove -y iwl* *firmware* --exclude=kernel-firmware
    #卸载防火墙

构建好yum源
yum clean all
rm -rf /var/cache/yum
    #清空yum源缓存

2.打包镜像

复制代码
tar --numeric-owner --exclude=/proc --exclude=/sys --exclude=/mnt --exclude=/var/cache --exclude=/usr/share/{foomatic,backgrounds,perl5,fonts,cups,qt4,groff,kde4,icons,pixmaps,emacs,gnome-background-properties,sounds,gnome,games,desktop-directories} --exclude=/var/log -zcvf /mnt/CentOS-7.4-BaseImage.tar.gz /
    ##排除一些目录,因为那些目录会在机器启动后被创建打包文件系统

3.导入镜像

复制代码
cat CentOS-7.4-BaseImage.tar.gz | docker import - centos-tar:7.6.1810
    #找一台有docker环境的机器,将打包的tar.gz包构建为镜像。

docker images
    #查看导入的镜像

4.运行容器

复制代码
docker run --name centos -it -p 80:80 centos-tar:7.6.1810 /bin/bash
    #基于centos-tar:7.6.1810镜像运行容器,并进入容器。

yum -y install httpd
    #在容器内安装httpd服务

httpd
    #启动httpd网页服务

浏览器访问物理机IP测试
相关推荐
Sokach10151 小时前
Linux Shell 脚本从零到能用:一个新手的一天学习总结
linux
SelectDB16 小时前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
AlfredZhao17 小时前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
曲幽1 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
zzzzzz3102 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode2 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220703 天前
如何搭建本地yum源(上)
运维
武子康3 天前
调查研究-183 Apple container:Mac 上用轻量 VM 跑 Linux 容器,Swift 会改写本地容器体验吗?
docker·容器·apple
A小辣椒4 天前
TShark:Wireshark CLI 功能
linux
A小辣椒4 天前
TShark:基础知识
linux