Closed sklose closed 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!
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 -
Thanks! This is great information to have. I really appreciate you taking the time to share it. I'll add this to the docs.
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) orC:\Users
(Windows) directory - and so you can mount files or directories usingdocker run -v /Users/<path>:/<container path> ...
(OS X) ordocker 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
I am trying to build my resume as pdf from within a docker container. I am getting this error
Is there a workaround for this? My Dockerfile looks like this
The output I get is this
... it says the pdf was created, but it's actually not