Xvfb& Docker - 无法打开显示

时间:2015-08-22 00:22:21

标签: firefox docker dockerfile xvfb

我需要使用firefox运行XVFB和docker,但无法让它们一起工作

这是我的Dockerfile:

FROM abevoelker/ruby:latest # based on ubuntu
ENV TERM linux
RUN apt-get update && apt-get install -y .....

ENV DISPLAY :99

# Install Xvfb init script
ADD xvfb_init /etc/init.d/xvfb # default xvfb init.d
RUN chmod a+x /etc/init.d/xvfb

CMD ["firefox"]

我从Firefox获得的错误消息是

 Error: cannot open display: :99

1 个答案:

答案 0 :(得分:11)

I solved this by writing a startup script which will:

  1. start xvfb
  2. start firefox

Executing the script via CMD allows the proper sequence of commands to run on container startup.

Dockerfile

...
ENV DISPLAY :99

ADD run.sh /run.sh
RUN chmod a+x /run.sh

CMD /run.sh

run.sh

Xvfb :99 -screen 0 640x480x8 -nolisten tcp &
firefox