there4 / markdown-resume

Generate a responsive CSS3 and HTML5 resume with Markdown, with optional PDF output.
MIT License
1.77k stars 519 forks source link

Run md2resume in docker #46

Closed sklose closed 9 years ago

sklose commented 9 years ago

I am trying to build my resume as pdf from within a docker container. I am getting this error

QXcbConnection: Could not connect to display

Is there a workaround for this? My Dockerfile looks like this

FROM php:5-cli
VOLUME /out
ENV DEBIAN_FRONTEND noninteractive
RUN docker-php-ext-install mbstring
RUN apt-get update && apt-get -qqy install wget wkhtmltopdf
RUN wget https://github.com/there4/markdown-resume/raw/master/bin/md2resume && chmod +x md2resume
CMD ./md2resume html /out/sklose.md /out/html && ./md2resume pdf /out/sklose.md /out/pdf

The output I get is this

Wrote resume to: /out/html/sklose.html
QXcbConnection: Could not connect to display
Aborted (core dumped)
Wrote pdf resume to: /out/pdf/sklose.pdf

... it says the pdf was created, but it's actually not

craig-davis commented 9 years ago

I would guess that the webkit tooling (wkhtmltopdf) is trying to connect to a display. I'm not sure if wkhtmltopdf supports running in a headless mode. I'd start by investigating that. Let me know what you find!

sklose commented 9 years ago

I finally found a way to do it, in case somebody else is interested:

Dockerfile

FROM php:5-cli
VOLUME /out
ENV DEBIAN_FRONTEND noninteractive
RUN docker-php-ext-install mbstring
RUN apt-get update && apt-get -qqy install wget wkhtmltopdf
RUN wget https://github.com/there4/markdown-resume/raw/master/bin/md2resume && chmod +x md2resume
CMD ./md2resume html /out/sklose.md /out/html && ./md2resume pdf /out/sklose.md /out/pdf

Bash scrip to run everything:

#!/bin/bash
docker build -t sklose/resume .
mkdir -p html
mkdir -p pdf
xhost + # this is required for the conatiner to access our local X-Server
docker run --rm -t -i -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:ro -v $PWD:/out:rw sklose/resume
sudo chown -R sebastian .
xhost -
craig-davis commented 9 years ago

Thanks! This is great information to have. I really appreciate you taking the time to share it. I'll add this to the docs.

artem-frolov commented 8 years ago

Thanks, @sklose! There is an easier way that can be used on any OS including Windows and Mac OS.

Dockerfile

FROM php:5-cli
VOLUME /out
ENV DEBIAN_FRONTEND noninteractive
RUN docker-php-ext-install mbstring
RUN apt-get update && apt-get -qqy install wget wkhtmltopdf xvfb
RUN wget https://github.com/there4/markdown-resume/raw/master/bin/md2resume && chmod +x md2resume
CMD ./md2resume html /out/resume.md /out/html && xvfb-run ./md2resume pdf /out/resume.md /out/pdf

Bash script

#!/bin/bash
docker build -t your/resume .
mkdir -p html
mkdir -p pdf
docker run --rm -t -i -e DISPLAY -v $PWD:/out:rw your/resume
sudo chown -R youruser .

Windows/Mac OS users, keep in mind the following note from the Docker user guide:

If you are using Docker Machine on Mac or Windows, your Docker daemon only has limited access to your OS X/Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory - and so you can mount files or directories using docker run -v /Users/<path>:/<container path> ... (OS X) or docker run -v /c/Users/<path>:/<container path ... (Windows). All other paths come from your virtual machine’s filesystem.

So on Windows docker run --rm -t -i -e DISPLAY -v $PWD:/out:rw your/resume should look like docker run --rm -t -i -e DISPLAY -v /c/Users/youruser/resumedir/:/out:rw your/resume