Building an Ubuntu Desktop in Docker

To build an Ubuntu Desktop in Docker, we will be creating our own docker image with the “docker build” command.

To do this, edit a file named dockerfile:

nano dockerfile

In the video, we used the following content. Make changes for your specific needs:

FROM ubuntu:latest

RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y lubuntu-desktop

RUN rm /run/reboot-required*

RUN useradd -m scott -p $(openssl passwd testing)
RUN usermod -aG sudo scott

RUN apt install -y xrdp
RUN adduser xrdp ssl-cert

RUN sed -i '3 a echo "\
export GNOME_SHELL_SESSION_MODE=lubuntu\\n\
export XDG_SESSION_TYPE=x11\\n\
export XDG_CONFIG_DIRS=/etc/xdg/xdg-Lubuntu:/etc/xdg\\n\
" > ~/.xsessionrc' /etc/xrdp/


CMD service xrdp start ; bash 

Build your image and name it. Mine is named “desktop”:

docker build -t desktop .

List your docker images:

Run your desktop using the address of the docker host:

docker run -it -d --name=mydesktop -p 3389:3389 desktop

To create another container using the same image, but offering this container on the LAN, we create a docker network as in the previous video:

docker network create -d macvlan --subnet= --gateway= -o parent=enp4s0 exposed

Start the container on your MAIN LAN using the “exposed” network:

docker run -it -d --name=lan-desktop --net=exposed  --ip= desktop

Remember to change the parent Ethernet device to match yours and the addresses to match your network in the examples above. Review my video entitled, “Docker Networking”