如何使用docker构建我自己的自定义Ubuntu ISO
作为背景,我有一个自定义的Ubuntu LiveUSB,它将自动引导到“Try it”中,操作系统将预装应用程序,我已将这些应用程序烧录到ISO中 它工作得很好,但我在自动化过程中不断遇到问题 我不是每次都手工操作(因为我的bash脚本在不久后第一次尝试时会得到不同的结果),而是考虑使用ISO中已解压缩的文件生成一个docker映像,以备修改,然后在卷中运行一个包含脚本的容器(docker run-v$(pwd)/bin:/data myimage/data/myscript.sh),它将修改内容,将其打包到ISO中,并将ISO保存在/data中以供我获取和分发如何使用docker构建我自己的自定义Ubuntu ISO,docker,docker-compose,dockerfile,Docker,Docker Compose,Dockerfile,作为背景,我有一个自定义的Ubuntu LiveUSB,它将自动引导到“Try it”中,操作系统将预装应用程序,我已将这些应用程序烧录到ISO中 它工作得很好,但我在自动化过程中不断遇到问题 我不是每次都手工操作(因为我的bash脚本在不久后第一次尝试时会得到不同的结果),而是考虑使用ISO中已解压缩的文件生成一个docker映像,以备修改,然后在卷中运行一个包含脚本的容器(docker run-v$(pwd)/bin:/data myimage/data/myscript.sh),它将修改内
FROM ubuntu:16.04
MAINTAINER Myself
ENV ISO_FILE="ubuntu-16.04.3-desktop-amd64.iso" \
OS_VERSION="16.04.3"
RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y squashfs-tools genisoimage gnupg2 \
nodejs rsync build-essential libc6-dev-i386 \
wget
# Make directories
RUN mkdir /data
RUN mkdir -p /root/workspace
# Download ubuntu iso
WORKDIR /root/workspace
RUN wget http://releases.ubuntu.com/$OS_VERSION/$ISO_FILE
RUN wget http://releases.ubuntu.com/$OS_VERSION/SHA256SUMS
RUN wget http://releases.ubuntu.com/$OS_VERSION/SHA256SUMS.gpg
# Check hash (default /bin/sh errors out)
RUN /bin/bash -c "sha256sum -c <(grep $ISO_FILE SHA256SUMS)"
# Check signatures
RUN gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 0xFBB75451 0xEFE21092
RUN gpg2 --verify SHA256SUMS.gpg SHA256SUMS
# Create mount
RUN mkdir mnt
# Here is where the docker build fails
RUN mount -o loop $ISO_FILE mnt
# Extract official DVD
RUN mkdir extract-cd
RUN rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd
RUN unsquashfs mnt/casper/filesystem.squashfs
RUN mv squashfs-root edit
RUN umount mnt
# Insert buildscript and make it executable
COPY bin/buildscript.sh /root/workspace/edit/buildscript.sh
RUN chmod +x edit/buildscript.sh
# Prepare to chroot into unsquashed ubuntu image, and run buildscript.sh
RUN mount -o bind /run/ edit/run
RUN mount --bind /dev/ edit/dev
RUN chroot edit/ ./buildscript.sh
# unmount the mountpoints and delete the buildscript.
RUN umount edit/dev
RUN umount edit/run
RUN rm edit/buildscript.sh
由于这不起作用,我在网上发现build-run-commit方法可能会起作用。。。因此,我将dockerfile的结尾更改为
# Create mount
RUN mkdir mnt
RUN mkdir extract-cd
COPY bin/buildscript.sh /root/workspace/buildscript.sh
COPY bin/build_run_step2.sh /root/workspace/build_run_step2.sh
RUN chmod +x buildscript.sh
RUN chmod +x build_run_step2.sh
然后build run commit的“run”步骤是build_run_step2.sh,它具有以下内容(使用--privileged运行)
哪个有效。。。但后来我遇到了一个问题:
运行apt get update时出错:
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
检查ping会在chrooted时显示“找不到主机”
因此,一个主要问题和一个较小的问题(如果主要问题没有答案):
如果尚未更新源列表,则可能会发生这种情况。尝试:
sudo apt update
所以万一有人找到这个帖子。解决dns问题的方法是确保chroot中的resolv.conf文件实际上指向正确的dns服务器。一些像cubic这样的应用已经为你做了这些 我取得了进展:通过在运行步骤之前安装dig,我能够挖掘chroot脚本所需的所有域。(主要是archive.ubuntu.com和security.ubuntu.com)并手动将它们添加到/etc/hosts。我知道您的操作说明。它们是次优的。您可以通过使用
xorriso-osirrox on-indev$ISO_FILE-extract/extract cd
将ISO直接解压到extract cd
(然后在解除解压后删除mnt/casper/filesystem.squashfs
)来消除对rsync和其中一个绑定挂载的需要通过使用-d edit
调用unsquashfs,您可以跳过mv squashfs root edit
。
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
sudo apt update