Skip to content

Commit 3ba8292

Browse files
committed
Extract Docker CMD into separate entrypoint.sh script for cleaner Dockerfile
1 parent 2a99d94 commit 3ba8292

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ ENV VERSION=${VERSION}
1111
# Copy the public directory contents to the nginx html directory
1212
COPY public/ /usr/share/nginx/html/
1313

14+
# Copy entrypoint script
15+
COPY entrypoint.sh /entrypoint.sh
16+
RUN chmod +x /entrypoint.sh
17+
1418
# Create symlink for cleaner volume mounting
1519
RUN ln -s /data /usr/share/nginx/html/data
1620

@@ -23,5 +27,5 @@ COPY nginx.conf /etc/nginx/nginx.conf
2327
# Expose port 80
2428
EXPOSE 80
2529

26-
# Start nginx with envsubst to inject environment variables
27-
CMD ["/bin/sh", "-c", "envsubst '${SEARCH_HIGHLIGHT_LIMIT}' < /usr/share/nginx/html/index.html > /usr/share/nginx/html/index.html.tmp && mv /usr/share/nginx/html/index.html.tmp /usr/share/nginx/html/index.html && nginx -g 'daemon off;'"]
30+
# Start the application
31+
CMD ["/entrypoint.sh"]

entrypoint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
# Substitute environment variables in index.html
3+
envsubst '${SEARCH_HIGHLIGHT_LIMIT}' < /usr/share/nginx/html/index.html > /usr/share/nginx/html/index.html.tmp
4+
mv /usr/share/nginx/html/index.html.tmp /usr/share/nginx/html/index.html
5+
6+
# Start nginx
7+
nginx -g 'daemon off;'

0 commit comments

Comments
 (0)