下面這個Dockerfile可以建立一個具備ssh server及X11 server的docker容器。可以在裡面執行一般的X11的程式並且透過X11 client看到畫面。
FROM centos:centos7
MAINTAINER Gary Lee <garywlee@gmail.com>
# Install ssh server.
RUN yum install -y which openssh-clients openssh-server
RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN sed -i '/pam_loginuid.so/c session optional pam_loginuid.so' /etc/pam.d/sshd
# Set root's password
RUN echo "centos" | chpasswd
# Add user
RUN useradd user1 -p iamuser1
# Install system tools and libraries.
RUN yum -y install glibc.i686
RUN yum -y install libstdc++.so.6
RUN yum -y install net-tools
# Install X Window System
# yum -y groupinstall "X Window System" "Desktop" "Fonts" "General Purpose Desktop"
RUN yum -y groupinstall "X Window System" "Fonts"
# Install other tools.
RUN yum -y install xterm
RUN yum -y install gedit
RUN yum -y install gvim
RUN yum -y install okular
RUN yum -y install vim
# Expose settings.
EXPOSE 22
ENTRYPOINT ["/usr/sbin/sshd", "-D"]