Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +23 -12
Dockerfile
CHANGED
|
@@ -2,18 +2,22 @@ FROM nikolaik/python-nodejs:python3.9-nodejs18
|
|
| 2 |
|
| 3 |
USER root
|
| 4 |
|
|
|
|
| 5 |
RUN apt-get -y update && apt-get -y install nginx xvfb openssh-server
|
| 6 |
|
|
|
|
| 7 |
RUN mkdir -p /var/cache/nginx \
|
| 8 |
/var/log/nginx \
|
| 9 |
/var/lib/nginx
|
| 10 |
RUN touch /var/run/nginx.pid
|
| 11 |
|
|
|
|
| 12 |
RUN chown -R pn:pn /var/cache/nginx \
|
| 13 |
/var/log/nginx \
|
| 14 |
/var/lib/nginx \
|
| 15 |
/var/run/nginx.pid
|
| 16 |
|
|
|
|
| 17 |
USER pn
|
| 18 |
ENV HOME=/home/pn \
|
| 19 |
PATH=/home/pn/.local/bin:$PATH
|
|
@@ -22,24 +26,31 @@ RUN mkdir $HOME/app
|
|
| 22 |
|
| 23 |
WORKDIR $HOME/app
|
| 24 |
|
|
|
|
| 25 |
RUN npm install --save express ws
|
| 26 |
|
|
|
|
| 27 |
COPY --chown=pn nginx.conf /etc/nginx/sites-available/default
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
# Optionally, set permissions for the .ssh directory and keys
|
| 36 |
-
RUN chmod 700 /home/pn/.ssh && \
|
| 37 |
chmod 600 /home/pn/.ssh/id_rsa && \
|
| 38 |
chmod 644 /home/pn/.ssh/id_rsa.pub
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
| 2 |
|
| 3 |
USER root
|
| 4 |
|
| 5 |
+
# Install necessary packages
|
| 6 |
RUN apt-get -y update && apt-get -y install nginx xvfb openssh-server
|
| 7 |
|
| 8 |
+
# Prepare Nginx directories
|
| 9 |
RUN mkdir -p /var/cache/nginx \
|
| 10 |
/var/log/nginx \
|
| 11 |
/var/lib/nginx
|
| 12 |
RUN touch /var/run/nginx.pid
|
| 13 |
|
| 14 |
+
# Change ownership to non-root user
|
| 15 |
RUN chown -R pn:pn /var/cache/nginx \
|
| 16 |
/var/log/nginx \
|
| 17 |
/var/lib/nginx \
|
| 18 |
/var/run/nginx.pid
|
| 19 |
|
| 20 |
+
# Switch to non-root user
|
| 21 |
USER pn
|
| 22 |
ENV HOME=/home/pn \
|
| 23 |
PATH=/home/pn/.local/bin:$PATH
|
|
|
|
| 26 |
|
| 27 |
WORKDIR $HOME/app
|
| 28 |
|
| 29 |
+
# Install necessary npm packages
|
| 30 |
RUN npm install --save express ws
|
| 31 |
|
| 32 |
+
# Copy Nginx configuration
|
| 33 |
COPY --chown=pn nginx.conf /etc/nginx/sites-available/default
|
| 34 |
|
| 35 |
+
# SSH Setup
|
| 36 |
+
# Create the .ssh directory and generate SSH key pair non-interactively
|
| 37 |
+
RUN mkdir -p /home/pn/.ssh && \
|
| 38 |
+
ssh-keygen -t rsa -b 4096 -f /home/pn/.ssh/id_rsa -N "" && \
|
| 39 |
+
chmod 700 /home/pn/.ssh && \
|
|
|
|
|
|
|
|
|
|
| 40 |
chmod 600 /home/pn/.ssh/id_rsa && \
|
| 41 |
chmod 644 /home/pn/.ssh/id_rsa.pub
|
| 42 |
|
| 43 |
+
# Expose SSH port (usually port 22)
|
| 44 |
+
EXPOSE 22
|
| 45 |
+
|
| 46 |
+
# Switch back to root for running SSH daemon and Nginx
|
| 47 |
+
USER root
|
| 48 |
+
|
| 49 |
+
# Start SSH manually without systemctl
|
| 50 |
+
RUN mkdir /var/run/sshd
|
| 51 |
|
| 52 |
+
# Expose Nginx port (default port 80)
|
| 53 |
+
EXPOSE 80
|
| 54 |
|
| 55 |
+
# Ensure services start correctly
|
| 56 |
+
CMD ["/usr/sbin/sshd", "-D"] # Starts the SSH server in the foreground
|