10

Working with Docker and I notice almost everywhere the "RUN" command starts with an apt-get upgrade && apt-get install etc.

What if you don't have internet access and simply want to do a "dpkg -i ./deb-directory/*.deb" instead?

Well, I tried that and I keep failing. Any advice would be appreciated:

  dpkg: error processing archive ./deb-directory/*.deb (--install):
  cannot access archive: No such file or directory
 Errors were encountered while processing: ./deb-directory/*.deb
 INFO[0002] The command [/bin/sh -c dpkg -i ./deb-directory/*.deb] returned a non-zero code: 1`

To clarify, yes, the directory "deb-directory" does exist. In fact it is in the same directory as the Dockerfile where I build.

Vrakfall
  • 966
  • 7
  • 13
user3614014
  • 653
  • 1
  • 6
  • 22
  • 2
    Please post your Dockerfile, maybe you need to *ADD* the deb File ? – svenhornberg Feb 11 '15 at 14:38
  • That is not an ideal solution, if I have 85 deb files I want to install, do I need to ADD 85 times? – user3614014 Feb 11 '15 at 16:00
  • 2
    ADD can also copy a directory not only files, so you dont need to copy 85 files. But anyway its easier if you post your Dockerfile or a minimal example like an ubuntu and one deb file, so someone/we can reproduce and learn from your error. – svenhornberg Feb 11 '15 at 16:17
  • The Docker file is only required to build containers. Connect the build machine to the internet and built images will work fine without an externel network. – Mark O'Connor Feb 11 '15 at 22:08
  • it doesn't directly answer your question, but an apt repo would solve all your issues here, assuming your packages have their dependencies right and all that. – figtrap Mar 05 '18 at 16:26

1 Answers1

8

This is perhaps a bug, I'll open a ticket on their github to know. Edit: I did it here.

Edit2: Someone answered a better way of doing this on the github issue.

* is a shell metacharacter. You need to invoke a shell for it to be expanded.

docker run somecontainer sh -c 'dpkg -i /debdir/*.deb'

!!! Forget the following but I leave it here to keep track of my reflexion steps !!!

The problem comes from the * statement which doesn't seem to work well with the docker run dpkg command. I tried your command inside a container (using an interactive shell) and it worked well. It looks like dpkg is trying to install the so called ./deb-directory/*.deb file which doesn't exist instead of installing all the .deb files contained there.

I just implemented a workaround. Copy a .sh script in your container, chmod +x it and then use it as your command. (FYI, prefer using COPY instead of ADD when the file isn't remotely copied. Check the best practices for writing Dockerfiles for more info.)

This is my Dockerfile for example purpose:

FROM debian:latest
MAINTAINER Vrakfall <jeremy@artphotolaurent.be>

COPY install.sh /
#debdir is a directory
COPY debdir /debdir
RUN chmod +x /install.sh

CMD ["/install.sh"]

The install.sh (copied at the root directory) simply contains:

#!/bin/bash
dpkg -i /debdir/*.deb

And the following

docker build -t debiantest .
docker run debiantest

works well and install all the packages contained in the /debdir directory.

Vrakfall
  • 966
  • 7
  • 13