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_CURRENT_DESKTOP=LXQt\\n\
export XDG_CONFIG_DIRS=/etc/xdg/xdg-Lubuntu:/etc/xdg\\n\
" > ~/.xsessionrc' /etc/xrdp/startwm.sh

EXPOSE 3389

CMD service xrdp start ; bash 

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

docker build -t desktop .

List your docker images:
image

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=172.16.0.0/16 --gateway=172.16.0.1 -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=172.16.1.200 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”