Skip to content

Instantly share code, notes, and snippets.

@mathematicalmichael
Last active June 29, 2024 05:24
Show Gist options
  • Save mathematicalmichael/5fa05ed2f2350f1577a46cec11746d5b to your computer and use it in GitHub Desktop.
Save mathematicalmichael/5fa05ed2f2350f1577a46cec11746d5b to your computer and use it in GitHub Desktop.
custom-source-Dockerfile
# Use a base Debian image
FROM debian:latest
# Define an argument for the repository URL
ARG REPO_URL=http://localhost:9221
# Replace default Debian repository with a local mirror
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak \
&& sed -i "s|http://deb.debian.org/debian|${REPO_URL}/debian|g" /etc/apt/sources.list \
&& sed -i "s|http://security.debian.org/debian-security|${REPO_URL}/debian-security|g" /etc/apt/sources.list
# Remove problematic debian-security entries if they do not exist
RUN sed -i '/debian-security/d' /etc/apt/sources.list
# Update the package list and install vim
RUN apt-get update && apt-get install -yqq \
curl \
vim \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Use a base Debian image
FROM debian:latest
# Define an argument for the repository URL
ARG REPO_URL=http://localhost:9221
# Backup the original sources.list, then modify it
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak \
&& sed -i "s|http://deb.debian.org/debian|${REPO_URL}/debian|g" /etc/apt/sources.list \
&& sed -i "s|http://security.debian.org/debian-security|${REPO_URL}/debian-security|g" /etc/apt/sources.list \
&& sed -i '/debian-security/d' /etc/apt/sources.list
# Install
RUN apt-get update \
&& apt-get install -yqq \
curl \
vim \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Restore
RUN cp /etc/apt/sources.list.bak /etc/apt/sources.list \
&& rm /etc/apt/sources.list.bak
# Use a base Debian image
FROM debian:latest
# Define an argument for the repository URL
ARG REPO_URL=http://localhost:9221
# Backup the original sources.list, modify it, install packages, cleanup, and restore the original sources.list
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak \
&& sed -i "s|http://deb.debian.org/debian|${REPO_URL}/debian|g" /etc/apt/sources.list \
&& sed -i "s|http://security.debian.org/debian-security|${REPO_URL}/debian-security|g" /etc/apt/sources.list \
&& sed -i '/debian-security/d' /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -yqq \
curl \
vim \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& cp /etc/apt/sources.list.bak /etc/apt/sources.list \
&& rm /etc/apt/sources.list.bak
# Use a base Debian image
FROM debian:latest
# Define an argument for the repository URL
ARG REPO_URL=http://localhost:9221
# Backup the original sources.list, then modify it
RUN curl ${REPO_URL}/update-lists.sh | sh
# Install
RUN apt-get update \
&& apt-get install -yqq \
curl \
vim \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Restore
RUN cp /etc/apt/sources.list.bak /etc/apt/sources.list \
&& rm /etc/apt/sources.list.bak
#!/bin/sh
cp /etc/apt/sources.list /etc/apt/sources.list.bak \
&& sed -i "s|http://deb.debian.org/debian|${REPO_URL}/debian|g" /etc/apt/sources.list \
&& sed -i "s|http://security.debian.org/debian-security|${REPO_URL}/debian-security|g" /etc/apt/sources.list \
&& sed -i '/debian-security/d' /etc/apt/sources.list
echo "Done."
cat /etc/apt/sources.list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment