skip to Main Content

I’m trying to install chrome in a docker container. I execute:

RUN apt-get install -y wget
RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i google-chrome-stable_current_amd64.deb  # problem here
RUN apt -f install -y

The problem is that dpkg -i fails because of missing dependencies. In principle this is not a big problem, as the next command should fix this, and indeed it does it when run interactively from within the container. But the problem is that when building a docker container this error makes the build process to stop:

dpkg: error processing package google-chrome-stable (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 google-chrome-stable
root@78b45ab9aa33:/# 
exit

How can I overcome this problem? Isn’t there a simpler way to install chrome without provoking the dependence problem? I can’t find the repository to add so I can run a regular apg-get install google-chrome, that is what I’d like to do. In the google linux repository they just mention that the "the packages will automatically configure the repository settings necessary". Which is not exactly what I get…

5

Answers


  1. Chosen as BEST ANSWER

    After the comment by @Facty and some more search, I found two solutions to install Google Chrome without raising this error. I'll post it below for future references or people having the same issue.

    There are actually two ways to install Chrome on a docker container:

    If you download the deb file manually, you can install it with apt-get instead of dpkg. This will automatically install the dependencies without having to call apt -f install -y later :

    RUN apt-get install -y wget
    RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    RUN apt-get install ./google-chrome-stable_current_amd64.deb
    

    The other solution is to add the repositories (installing the gpg key) and install from them directly, skipping the manual download:

    RUN apt-get install -y wget
    RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -  
        && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
    RUN apt-get update && apt-get -y install google-chrome-stable
    

  2. Here an example for Node versions (debian based)
    Dockerfile

    FROM node:16.16.0 as base
    # Chrome dependency Instalation
    RUN apt-get update && apt-get install -y 
        fonts-liberation 
        libasound2 
        libatk-bridge2.0-0 
        libatk1.0-0 
        libatspi2.0-0 
        libcups2 
        libdbus-1-3 
        libdrm2 
        libgbm1 
        libgtk-3-0 
    #    libgtk-4-1 
        libnspr4 
        libnss3 
        libwayland-client0 
        libxcomposite1 
        libxdamage1 
        libxfixes3 
        libxkbcommon0 
        libxrandr2 
        xdg-utils 
        libu2f-udev 
        libvulkan1
     # Chrome instalation 
    RUN curl -LO  https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
    RUN rm google-chrome-stable_current_amd64.deb
    # Check chrome version
    RUN echo "Chrome: " && google-chrome --version
    
    Login or Signup to reply.
  3. If you’re using it in Python, to run selenium. Here is what solved my problem.

    RUN apt -f install -y
    RUN apt-get install -y wget
    RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    RUN apt-get install ./google-chrome-stable_current_amd64.deb -y
    

    Sometimes, using wget doesn’t solve the problem. Due to lack of support. So you can use apt -f install -y

    The only mistake @Pythonist had was the disorder of commands.

    Login or Signup to reply.
  4. apt-get won’t work.

    You should use dpkg -i ./google-chrome.deb

    Login or Signup to reply.
  5. Note that some base images may have or not have wget or gnupg,
    so full working Dockerfile example is

    FROM ubuntu:22.04
    
    RUN apt-get update; apt-get clean
    
    # Install wget.
    RUN apt-get install -y wget
    
    RUN apt-get install -y gnupg
    
    # Set the Chrome repo.
    RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - 
        && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
    
    # Install Chrome.
    RUN apt-get update && apt-get -y install google-chrome-stable
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search