Skip to content

Commit 8a300aa

Browse files
committed
split ssh server setting into a seperate Dockerfile
1 parent 20732d5 commit 8a300aa

File tree

3 files changed

+73
-39
lines changed

3 files changed

+73
-39
lines changed

docker/Dockerfile_ppp_openmc

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# Changelog: 1) merge commands to improve performance
55
# 2) add gmsh, ppp, occ_faceter, freecad
66
# 3) both X11 and jupyter web interface should be supported
7-
# 4) ssh server
8-
# 5) base image can be selected from ubuntu:bionic (18.04), ubuntu:focal (20.04), jupyter/minimal-notebook
7+
# 4) base image can be selected from ubuntu:bionic (18.04), ubuntu:focal (20.04), jupyter/minimal-notebook
98
######################################
109
#
1110
# build with the following command
@@ -26,8 +25,6 @@ FROM jupyter/minimal-notebook
2625

2726
# only last CMD is working, if multiple CMD exists, interactive mode also suppress this CMD
2827
# jupyter can create a terminal, just like ssh
29-
# uncomment this CMD if the base image is not jupyter, assuming ssh server installation section is kept
30-
#CMD ["/usr/sbin/sshd","-D"]
3128

3229

3330
LABEL name="ppp_openmc" \
@@ -171,7 +168,7 @@ RUN cd /opt/openmc/ && python setup.py install && \
171168
cd .. && rm -rf build
172169

173170
## some python package is needed for openmc
174-
RUN pip install neutronics_material_maker --user
171+
RUN pip install neutronics_material_maker
175172

176173
# Oct 2020, openmc must be installed to /opt/openmc, to install this parametric-plasma-source
177174
RUN pip install git+https://github.com/open-radiation-sources/parametric-plasma-source.git
@@ -182,26 +179,6 @@ ENV LD_LIBRARY_PATH=$HOME/MOAB/lib:$HOME/DAGMC/lib
182179
ENV PATH=$PATH:$HOME/MOAB/bin:/opt/openmc/bin:$HOME/DAGMC/bin
183180

184181

185-
####################
186-
install ssh server
187-
####################
188-
RUN apt install openssh-server nano -y
189-
190-
# to enable X11 forwarding via ssh
191-
RUN echo "ForwardX11 yes" >> /etc/ssh/ssh_config && echo "ForwardX11Trusted no" >> /etc/ssh/ssh_config
192-
193-
# use UID 1001, as 1000 has been used by another user
194-
RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1001 test
195-
196-
# set password for the user test as "test"
197-
RUN echo 'test:test' | chpasswd
198-
RUN service ssh start
199-
200-
# expose port, the default
201-
EXPOSE 22
202-
##################
203-
204-
205182
##############
206183
## install gmsh and pygmsh
207184
##############
@@ -262,6 +239,10 @@ ENV OPENMC_CROSS_SECTIONS=$MAT_DIR/cross_sections.xml
262239
# for jupyter to work: switch to USER $NB_USER
263240
USER $NB_USER
264241

242+
# for ssh login user to have path setup
243+
RUN echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/MOAB/lib:$HOME/DAGMC/lib" >> $HOME/.bashrc
244+
RUN echo "export PATH=$PATH:$HOME/MOAB/bin:/opt/openmc/bin:$HOME/DAGMC/bin" >> $HOME/.bashrc
245+
265246
RUN git clone -b develop https://github.com/ukaea/openmc_workshop
266247
# currently there is some bug stop install parametric_plasma_source
267248
#RUN cd openmc_workshop && pip install -r requirements.txt

docker/Dockerfile_ssh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# this layer add ssh, X11 forwarding, sudo capacity
2+
# it can be based on any image, to add ssh access feature
3+
# mkdir .ssh
4+
# ssh-keygen -b 1024 -t rsa -f .ssh/ssh_host_key_rsa
5+
# build with the following command (in the folder where pubkey has been generated)
6+
# sudo docker build -f Dockerfile_ssh -t ppp_openmc_ssh . --no-cache
7+
8+
# To test ssh X11Forwarding
9+
# 1) client must have been tested to be working with X11 forwarding with other remote ssh server
10+
# debug connection by -v option `ssh -vv -Y -p 2222 [email protected]`
11+
# 2) user root is not usually allowed to do X11 forwarding,
12+
#
13+
# if can not open DISPLAY, check if -X or -Y option has been set in ssh client command
14+
#
15+
# error "X11 forwarding request failed on channel 0"
16+
# solved by adding `X11UseLocalhost no` `X11Forwarding yes` to /etc/ssh/sshd_config
17+
############################################################################
18+
19+
FROM qingfengxia/ppp_openmc
20+
21+
USER root
22+
23+
####################
24+
# install ssh server
25+
####################
26+
RUN apt-get install openssh-server nano -y
27+
28+
################# ssh user ####################
29+
30+
31+
# change password, add to sudo group
32+
RUN echo 'jovyan:test' | chpasswd && usermod -aG sudo $NB_USER
33+
34+
# Allow members of group sudo to execute any command
35+
# TAB key causes some trouble, use more spaces before "ALL=" seems working
36+
RUN echo "%sudo ALL=(ALL:ALL) ALL" >> /etc/sudoers
37+
# if above still not working add this user to /etc/sudoers
38+
#RUN echo "$NB_USER ALL=(ALL:ALL) ALL" >> /etc/sudoers
39+
40+
############### host key setup #################
41+
# https://nickjanetakis.com/blog/docker-tip-56-volume-mounting-ssh-keys-into-a-docker-container
42+
# copy the ssh key from host, so to fix the host public key when rebuilding the image
43+
44+
COPY .ssh /root/.ssh
45+
RUN chmod 700 /root/.ssh && \
46+
chmod 644 /root/.ssh/ssh_host_key_rsa.pub && \
47+
chmod 600 /root/.ssh/ssh_host_key_rsa
48+
49+
RUN cp /root/.ssh/ssh_host_key_rsa.pub /etc/ssh/ && \
50+
cp /root/.ssh/ssh_host_key_rsa /etc/ssh/
51+
52+
# sshd_config has been modified by adding those lines
53+
# to enable X11 forwarding via ssh, by default has been enabled
54+
RUN echo "X11Forwarding yes" >> /etc/ssh/sshd_config && echo "X11UseLocalhost no" >> /etc/ssh/sshd_config
55+
RUN echo "HostKey /etc/ssh/ssh_host_key_rsa" >> /etc/ssh/sshd_config
56+
57+
# expose port, the default port
58+
EXPOSE 22
59+
##################
60+
61+
62+
CMD ["/usr/sbin/sshd", "-D"]
63+
64+
65+
USER $NB_USER

wiki/BuildOnLinux.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,7 @@ yum install opencascade-draw, opencascade-foundation, opencascade-modeling, op
170170

171171
#### Option 2: Download the opencascade source code and compile from source.
172172

173-
if not in package repository
174-
175-
```bash
176-
###### dependencies needed to build OpenCASCADE from source ##########
177-
# for OpenCASCADE, openGL is needed
178-
yum install tbb tbb-devel freetype freetype-devel freeimage freeimage-devel -y \
179-
&& yum install libXmu-devel libXi-devel glew-devel SDL2-devel SDL2_image-devel glm-devel -y
180-
# install those below if draw module is enabled for building OpenCASCADE
181-
yum install tk tcl tk-devel tcl-devel -y
182-
183-
# package name distinguish capital letter, while debian name is just libxmu
184-
yum install openmpi-devel boost-devel -y
185-
```
173+
Compile opencascade if not available in package repository, e.g. centos 7/8, see the "Dockerfile_centos" file for updated instructions.
186174

187175
To get the latest source code from [OCCT official website](https://www.opencascade.com/), you need register (free of charge). Registered user may setup public ssh key and get readonly access to the occt repo
188176
`git clone -b V7_4_0p1 [email protected]:occt occt`
@@ -200,7 +188,7 @@ tar -xzf occt.tar.gz
200188
cd occt-*
201189
mkdir build
202190
cd build
203-
cmake ..
191+
cmake .. -DUSE_TBB=ON -DBUILD_MODULE_Draw=OFF
204192
make -j$(nproc)
205193
sudo make install
206194
# by default install to the prefix: /usr/local/

0 commit comments

Comments
 (0)