If you have a headless machine (ie: no monitor plugged into it) you’ll need to either install a “HDMI headless dummy connector” or you can install a Video Dummy Package:
sudo apt-get install xserver-xorg-video-dummy
Then add a configuration file for it:
sudo vi /usr/share/X11/xorg.conf.d/xorg.conf
and paste this (adjusting your desired resolution)
Section "Device"
Identifier "Configured Video Device"
Driver "dummy"
EndSection
Section "Monitor"
Identifier "Configured Monitor"
HorizSync 31.5-48.5
VertRefresh 50-70
EndSection
Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1920x1080"
EndSubSection
EndSection
Then reboot the machine and voilá