How to run firefox inside docker container

0 votes

I have one docker container in my centos base system. But I am not able to run firefox from my container.

How can I do that?

Apr 16, 2020 in Docker by akhtar
• 38,240 points

1 answer to this question.

0 votes


Generally, if you run firefox inside docker container you will get the below error.

[root@1c3a22e43538 /]# firefox
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Running without a11y support!
Error: no DISPLAY environment variable specified

But you can use firefox inside your docker container. Follow the below given steps.

  • Run xauth list command in your host machine and copy the cookies.

[root@vm1 ~]# xauth list
vm1/unix:0  MIT-MAGIC-COOKIE-1  b4c39c85be9a907749dd9395f4175b0d
  • Run docker container with environment variable Display and also mount /tmp/.X11-unix folder to your container.

[root@vm1 ~]# docker run -it --name firefox --net=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix centos:7 bash
[root@vm1 /]#
  • Install firefox and xauth inside container.

$ yum install firefox xauth
  • Add cookies that you copy from your host machine.

$ xauth add <cookies>
  • Run firefox inside docker container, it will work.

Hope this will help you.

answered Apr 16, 2020 by MD
• 95,440 points

interesting after:

$ podman run -it --name firefox --net=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix centos:7 bash
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0

Any idea why? (I'm using podman, but it should be the same. From your article it is not clear what should be done with xauth list - it is not used anywhere else)

thanks, Tomas


Docker or Podman are generally used for the lightweight environment. Docker is not made for the GUI application. But there are some ways that you can do. For example, you can export your firefox from the base system to the Docker container. So xauth is the way through which you can use firefox from your Docker or podman container. And xauth list command will show the cookies of your local system. You need to copy the cookie and add it to your container using xauth add command.

Sorry, but it's unclear what part of the cookie we should copy, and how to add it.

I just get:

"xauth: (argv):1:  bad "add" command line" not matter how I add the cookie.

Please use a full example to show how to do it


You need to copy the whole cookie from your host machine. As shown in the example.

vm1/unix:0  MIT-MAGIC-COOKIE-1  b4c39c85be9a907749dd9395f4175b0d

Copy the cookie and add the cookie to your docker-machine.

Related Questions In Docker

0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 10,610 points
0 votes
1 answer

How to run a cron job inside a docker container?

Hii, crond works well with tiny on Alpine RUN apk add --no-cache ...READ MORE

answered May 18, 2020 in Docker by Niroj
• 82,880 points
0 votes
2 answers

How to execute docker exec commande inside a docker container ?

You need to get inside the container ...READ MORE

answered Aug 13, 2019 in Docker by Sirajul
• 59,230 points
0 votes
1 answer

How to create a container and run images in docker?

Look for what all images you have ...READ MORE

answered Feb 23, 2019 in Docker by Kalgi
• 52,360 points
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,090 points
+1 vote
1 answer

How to run jenkins service inside docker container?

Hi@akhtar, By default systemctl command will not run ...READ MORE

answered May 12, 2020 in Docker by MD
• 95,440 points
+14 votes
19 answers

How can I run a ‘docker exec’ command inside a docker container?

you can run any command in a ...READ MORE

answered Dec 10, 2018 in Docker by Pramiti
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP