X-11 Into Docker

X-11 Into Docker
unsplash.com Credit Rob Potter

X-11 support into a running Docker container can be problematic - and many of the guides do not explain it very well.

  • Make a folder and make a file inside it named 'Dockerfile'
  • Inside your Dockerfile put:
FROM ubuntu:latest
ENV RED='\e[1;33m'
ENV CLR='\e[0m'

RUN printf "${RED}RUN apt-get update ${CLR}\n"
RUN sleep 2
RUN apt-get update

RUN printf "${RED} RUN ap-get install -y wget build-essential checkinstall${CLR}\n"
RUN sleep 2
RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y xserver-xorg-core
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y xserver-xorg
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y wget build-essential checkinstall nmap
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y xauth
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y openbox
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y xorg
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y systemctl
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y openssh-server
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y openssh-client
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y iproute2

# Add in root:Docker!  and docker:Docker!
RUN echo "root:Docker!" | chpasswd
RUN adduser docker
RUN echo "docker:Docker!" | chpasswd

Note: xauth, xserver-xorg-core etc are added.  You can also add more for firefox or your application of choice.

  • You can also see the commands for generic users you will add we have added root and docker with passwords Docker!

Now build it from inside the directory where your dockerfile sits:

docker build . -t <image name you want>

Once you have the image you can run it with:

docker run -it -d --privileged --net=host --name=<container name> <your built image> 

Note! docker can have close near commands:

sudo docker images ls
sudo docker image ls

Gives you something completely different.

Note! Because this docker is running with the same network as the host - it will overlap your ssh port 22. One would need to move it. Create a sshd_config file and put the following inside of it:


# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/us>

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

Port 222
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes128-ctr
#MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha>
KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group>

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/us>

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

Port 222
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes128-ctr
#MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha>
KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group>

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
  • Note we have enabled Port 222
  • We have also enabled root login

Insider your Dockerfile we will have to add the command

COPY sshd_config /etc/ssh/
Linux Rocks Every Day