60

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...

3
  • 2
    This might help: medium.com/dot-debug/…
    – Facty
    Commented Feb 2, 2022 at 12:37
  • It does! Thank you.
    – Pythonist
    Commented Feb 3, 2022 at 15:49
  • 3
    Cool, mind to share your Dockerfile with us? There can another person searching for answers :)
    – Facty
    Commented Feb 4, 2022 at 10:40

7 Answers 7

72

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 -y ./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
5
  • 2
    Both of them gets stuck on "Select a geographical area: " where it asks for a number as input. How to handle that any ideas? Commented Sep 8, 2022 at 11:39
  • 5
    @YaserSakkaf Add ENV DEBIAN_FRONTEND noninteractive to the Dockerfile.
    – slhck
    Commented Sep 13, 2022 at 7:51
  • For the first option (installing the deb file) you may also need apt-get update prior to installing it - at least this was the case for me.
    – Marcus
    Commented Mar 2, 2023 at 17:06
  • This no longer works as of April 7, 2024. dl.google.com/linux/chrome/deb/ is coming up 404.
    – Ken J
    Commented Apr 7 at 11:19
  • Adding the repositories is the simplest way that I've found so far. Skips all the dependency errors. Thank you!
    – Chris King
    Commented Jun 18 at 6:26
17

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
4
  • worked like charm on u20.04. thanks. all other answers here failed.
    – AhmFM
    Commented Apr 27, 2023 at 11:54
  • 1
    I get a ton of errors "requested an impossible situation" gist.github.com/fotoflo/954d68ebcd68c0eeab09283872f21637
    – fotoflo
    Commented Aug 18, 2023 at 20:27
  • @fotoflo It's look like you took shortcut and do not import "# Chrome dependency Installation" if you will do, the error will gone. Commented Aug 21, 2023 at 8:03
  • 2
    Even with adding "# Chrome dependency Installation", the issue remains. When I try to build the image using gcloud submit command, it works fine, however, with Docker, I get the same issue as @fotoflo
    – Idhem
    Commented Aug 22, 2023 at 8:57
5

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.

4
  • So you can instrument Chrome with a desktop-less linux? Commented Feb 20 at 19:56
  • 1
    Yes, in the case of deployment on terminal servers like AWS (EC2-Linux), DigitalOcean (droplet-Linux), or GCP (VM), etc. You only have the option to use the system from the terminal. there is no GUI by default, (although you can install GUI, but that slowdowns the instance) only option is to run the selenium without GUI. So you can use this method to use selenium. Commented Feb 20 at 22:15
  • add --fix-missing to the end of the apt-get install command to sort out any missing packages Commented Mar 20 at 12:19
  • 1
    An apt update before installing will ensure that there's apt cache. Otherwise you could get errors.
    – Ken J
    Commented Apr 7 at 11:24
3

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

2
  • 1
    Hii, Thanks. If I wanted to use a particular version of chrome (i.e 114), how do I implement that in the above snippet ? Commented Sep 14, 2023 at 11:08
  • Interesting to know - how to test any of these, as in, how do we know if the browser is installed/available? what version is installed?
    – Ak777
    Commented Jan 15 at 19:41
0

For selenium, and using the following docker base:

FROM python:3.11 as python-base

The following worked for me (Needed the --fix-missing) from an answer above.

# Install chrome for python selenium
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 --fix-missing
1
  • I needed to replace apt-get install with apt-get update && apt-get install - otherwise the wget package cannot be found Commented Apr 16 at 6:10
0

I solved the problem with

-6

apt-get won't work.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.