Docker image build hangs at "pacman -S ..."

I am trying to build a Docker image from the official Arch Linux image. These are the things I have done so far:

I PULL-ed the official Arch Linux Image:

docker pull base/archlinux

I wrote this "Dockerfile":

# Set base image
FROM base/archlinux:latest

# Fix mirrorlist file
#RUN rm /etc/pacman.d/mirrorlist
#RUN echo "Server = http://..." >> /etc/pacman.d/mirrorlist
#RUN echo "Server = http://..." >> /etc/pacman.d/mirrorlist
#RUN echo "Server = http://..." >> /etc/pacman.d/mirrorlist
#RUN echo "Server = http://..." >> /etc/pacman.d/mirrorlist

# Update pacman and install packages
RUN pacman-db-upgrade
RUN pacman -Syyu --noconfirm
RUN pacman -S --noconfirm nodejs phantomjs cronie

# Make cronjobs
RUN echo "*/2 * * * *   node /srv/visitor/visitor.js" >> mycronjobs
RUN echo "*/5 * * * *   killall -older-than 5m phantomjs" >> mycronjobs
RUN echo "0 0 * * *     rm /srv/visitor/visitor-info.log" >> mycronjobs
RUN crontab mycronjobs
RUN rm mycronjobs

# Fix hosts file
RUN echo "192.92.13.243 www.lololol.gr"

# Copy app code
COPY . /srv/visitor

# Install app dependencies
RUN cd /srv/visitor
RUN npm install

EXPOSE 80
CMD ["/bin/bash"]

What I want is the container to start at the command prompt, so that I can run in in interactive mode, and attach to it.

Now, I get this error at the time of building the image:

Step 3 : RUN pacman -S --noconfirm nodejs phantomjs cronie
 ---> Running in 30870b31aed6
error: failed to initialize alpm library
(database is incorrect version: /var/lib/pacman/)
error:   try running pacman-db-upgrade
INFO[0127] The command [/bin/sh -c pacman -S --noconfirm nodejs phantomjs cronie] returned a non-zero code: 255

What confuses me is that it looks like the package database is updated correctly, and the base system upgraded, and it hangs when trying to install three packages manually.

Any ideas?


Solution 1:

Well, I don't know Arch at all, but if you do this:

RUN pacman-db-upgrade

And then run this to upgrade your current packages:

RUN pacman -Syyu --noconfirm

It seems possible that you've just upgraded pacman and any other tools that touch the package database, so that when you run your next pacman command...

RUN pacman -S --noconfirm nodejs phantomjs cronie

...it fails because the package database has not been upgraded by the currently installed tools. I suspect you want to re-order those RUN statements:

RUN pacman -Syyu --noconfirm
RUN pacman-db-upgrade
RUN pacman -S --noconfirm nodejs phantomjs cronie