Issue
I have to do an installation of a few packages. The problem is the system will not have access to the internet. I can download all the dependent .deb files using
for i in $(apt-cache depends default-jre-headless | grep -E 'Depends|Recommends|Suggests' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do apt-get download $i 2>>errors.txt; done
But when I try to install it using apt install ./default-jre-headless
It does not search the local directory and goes online.
Is there any way to provide directory location for all .deb file to apt install command??
Or else a better solution would also be a great help.
Thanks!
Solution
Apparently I found the solution but forgot to mention here.
In order to make the local directory path for deb files and dependencies. We have to first download all the dependencies in any folder and after that run this command.
echo "Dir::Cache::Archives "/opt/packages/dep/";" | sudo tee -a /etc/apt/apt.conf
EDIT: Extending the answer for a better solution: Host the deb file on an Nginx Docker container. And Copy files from Ubuntu/CentOS image in the Nginx container.
Check out this gist: It has the Dockerfile for creating a dependent deb/rpm files in the image and moving it into an Nginx container. If you have some extra zip or tar file, it can also be included. Also, it has a conf file for reference. https://gist.github.com/ismail0352/e96d2cc94b71ef2324c9c0890ef7ca7f
A small part of it for reference:
# For Ubuntu
FROM ubuntu as ubuntu
RUN apt-get update
RUN apt-get install -y dpkg-dev wget gnupg2 curl
WORKDIR /opt/packages/deb
RUN apt update
RUN chown -R _apt /opt/packages/deb/
RUN apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances default-jre-headles | grep "^\w" | sort -u)
RUN dpkg-scanpackages . | gzip -9c > Packages.gz
# For Centos
FROM centos as centos
WORKDIR /opt/packages/rpm
RUN yum install wget curl epel-release createrepo yum-utils -y
RUN yum update -y
RUN yumdownloader --resolve java-1.8.0-openjdk-headless
# Nginx
FROM nginx
RUN apt-get update
RUN apt install wget -y
COPY nginx_default.conf /etc/nginx/conf.d/default.conf
WORKDIR /usr/share/nginx/html
COPY --from=ubuntu /opt/packages/ .
COPY --from=centos /opt/packages/ .
WORKDIR /usr/share/nginx/html/others/
RUN wget https://artifacts.elastic.co/downloads/logstash/logstash-7.3.1.zip
Answered By - Ismail