Ramses II commited on
Commit
e9576fd
1 Parent(s): 0d321d4
Files changed (1) hide show
  1. Dockerfile +41 -48
Dockerfile CHANGED
@@ -1,73 +1,66 @@
1
  FROM jupyter/scipy-notebook
2
 
3
- # Set the working directory to /app
4
- WORKDIR /app
5
 
6
- # Copy the requirements file
7
- COPY requirements.txt .
 
8
 
9
- # Copy static files
10
- COPY public /app/public
11
 
12
- # Switch to root user to install system packages and set permissions
13
  USER root
14
-
15
- # Install sudo and other dependencies
16
  RUN apt-get update && apt-get install -y \
17
  wget \
18
  nginx \
19
- sudo \
20
- build-essential \
21
- curl \
22
- git \
23
- vim \
24
  && apt-get clean && rm -rf /var/lib/apt/lists/*
25
 
26
- # Install Python dependencies
27
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
28
 
29
- # Add jovyan to sudoers
30
- RUN usermod -aG sudo jovyan && \
31
- echo "jovyan ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/jovyan && \
32
- chmod 0440 /etc/sudoers.d/jovyan
33
 
34
- # Copy the configuration files and entrypoint script
35
- COPY jupyter_config.py /etc/jupyter/jupyter_config.py
36
- COPY nginx.conf /etc/nginx/nginx.conf
37
- COPY entrypoint.sh /app/entrypoint.sh
38
 
39
- # Set the entrypoint script as executable
40
- RUN chmod +x /app/entrypoint.sh
41
 
42
- # Create necessary directories and set permissions for Nginx
 
43
  RUN mkdir -p /var/lib/nginx/body /var/lib/nginx/fastcgi \
44
  /var/lib/nginx/proxy /var/lib/nginx/scgi \
45
  /var/lib/nginx/uwsgi /var/log/nginx \
46
- && chown -R ${NB_UID}:${NB_GID} /var/lib/nginx /var/log/nginx /var/run /run \
47
  && chmod 755 /var/lib/nginx /var/run /run
48
 
49
- # Ensure Nginx has permissions to write to log directory and PID file
50
- RUN touch /var/log/nginx/error.log /var/log/nginx/access.log /run/nginx.pid \
51
- && chown -R ${NB_UID}:${NB_GID} /var/log/nginx /run/nginx.pid
52
-
53
- # Set the permissions for the app directory to the existing user
54
- RUN chown -R ${NB_UID}:${NB_GID} /app
55
-
56
- # Switch back to the original user
57
- USER ${NB_UID}
58
 
59
- # Set the working directory for the user
60
- WORKDIR /home/${NB_USER}/app
61
 
62
- # Expose the port 8888 for JupyterLab
63
- EXPOSE 8888
64
 
65
- # Expose the port 7860 for Nginx
66
- EXPOSE 7860
67
 
68
- # Set the environment variables
69
- ENV JUPYTERLAB_PORT=8888
70
- ENV NGINX_PORT=7860
71
 
72
- # Run the entrypoint script when the container starts
73
- ENTRYPOINT ["/app/entrypoint.sh"]
 
1
  FROM jupyter/scipy-notebook
2
 
3
+ # Create a user with ID 1000
4
+ RUN useradd -m -u 1000 user
5
 
6
+ # Set environment variables
7
+ ENV HOME=/home/user \
8
+ PATH=/home/user/.local/bin:$PATH
9
 
10
+ # Set working directory
11
+ WORKDIR $HOME/app
12
 
13
+ # Install system dependencies
14
  USER root
 
 
15
  RUN apt-get update && apt-get install -y \
16
  wget \
17
  nginx \
 
 
 
 
 
18
  && apt-get clean && rm -rf /var/lib/apt/lists/*
19
 
20
+ # Switch back to the user
21
+ USER user
22
+
23
+ # Upgrade pip
24
+ RUN pip install --no-cache-dir --upgrade pip
25
+
26
+ # Copy requirements and install Python dependencies
27
+ COPY --chown=user requirements.txt .
28
+ RUN pip install --user --no-cache-dir -r requirements.txt
29
 
30
+ # Copy static files
31
+ COPY --chown=user public $HOME/app/public
 
 
32
 
33
+ # Copy configuration files
34
+ COPY --chown=user jupyter_config.py $HOME/.jupyter/jupyter_config.py
35
+ COPY --chown=user nginx.conf $HOME/nginx.conf
36
+ COPY --chown=user entrypoint.sh $HOME/entrypoint.sh
37
 
38
+ # Make entrypoint executable
39
+ RUN chmod +x $HOME/entrypoint.sh
40
 
41
+ # Create necessary directories for Nginx
42
+ USER root
43
  RUN mkdir -p /var/lib/nginx/body /var/lib/nginx/fastcgi \
44
  /var/lib/nginx/proxy /var/lib/nginx/scgi \
45
  /var/lib/nginx/uwsgi /var/log/nginx \
46
+ && chown -R user:user /var/lib/nginx /var/log/nginx /var/run /run \
47
  && chmod 755 /var/lib/nginx /var/run /run
48
 
49
+ # Create Nginx log files
50
+ RUN touch /var/log/nginx/error.log /var/log/nginx/access.log \
51
+ && chown user:user /var/log/nginx/error.log /var/log/nginx/access.log
 
 
 
 
 
 
52
 
53
+ # Create a directory for persistent data
54
+ RUN mkdir -p /data && chown user:user /data && chmod 777 /data
55
 
56
+ USER user
 
57
 
58
+ # Expose ports
59
+ EXPOSE 8888 7860
60
 
61
+ # Set environment variables
62
+ ENV JUPYTERLAB_PORT=8888 \
63
+ NGINX_PORT=7860
64
 
65
+ # Run the entrypoint script
66
+ ENTRYPOINT ["$HOME/entrypoint.sh"]