use*_*620 5 docker dockerfile docker-compose
作为背景,我有一个自定义的 Ubuntu LiveUSB,它会自动启动到“试用”,操作系统将预装应用程序,我已经将这些应用程序刻录到 ISO 本身中。
它工作得很好,但我一直遇到自动化过程的问题。
而不是每次都手动完成,(因为我的 bash 脚本在我第一次再次尝试时不断得到不同的结果)我正在考虑使用准备修改的 ISO 中解压文件生成一个 docker 镜像,然后在卷中运行带有脚本的容器 (docker run -v $(pwd)/bin:/data myimage /data/myscript.sh),它将修改内容,将其打包回 ISO 并将 ISO 保存在 /数据供我抓取和分发。
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
Run Code Online (Sandbox Code Playgroud)
我在构建器中的 chroot 中运行的 buildscript.sh (或无法运行)是:
#!/bin/bash
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts
export HOME=/root
export LC_ALL=C
add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe multiverse"
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt install -y nodejs
apt upgrade -y
apt install -y chromium-browser git
apt install -y language-pack-ja language-pack-gnome-ja language-pack-ja-base language-pack-gnome-ja-base
localectl set-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja"
source /etc/default/locale
mkdir src
apt autoclean
rm -rf /tmp/* ~/.bash_history
umount /proc || umount -lf /proc
umount /sys
umount /dev/pts
exit
Run Code Online (Sandbox Code Playgroud)
由于这不起作用,我在网上发现 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
Run Code Online (Sandbox Code Playgroud)
然后构建运行提交的“运行”步骤是 build_run_step2.sh,它具有以下内容(使用 --privileged 运行)
#!/bin/bash
cd /root/workspace
mount -o loop $ISO_FILE mnt
# Extract official DVD
rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd
unsquashfs mnt/casper/filesystem.squashfs
mv squashfs-root edit
umount mnt
mv ./buildscript.sh edit/buildscript.sh
# Prepare to chroot into unsquashed ubuntu image, and run buildscript.sh
mount -o bind /run/ edit/run
mount --bind /dev/ edit/dev
chroot edit/ ./buildscript.sh
# unmount the mountpoints and delete the buildscript.
umount edit/dev
umount edit/run
rm edit/buildscript.sh
Run Code Online (Sandbox Code Playgroud)
哪个有效......但后来我遇到了一个问题:
运行 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'
Run Code Online (Sandbox Code Playgroud)
并在 chroot 时检查 ping 让我“找不到主机”。
所以一个主要问题和一个较小的问题(如果主要问题没有答案):
归档时间: |
|
查看次数: |
1477 次 |
最近记录: |