Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/serving/samples/hello-world/helloworld-nodejs/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Use the official Node.js 12 image.
# Use the official lightweight Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12
FROM node:12-slim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the choice of slim here, as it keeps the container closer to what developers expect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many developers are going to copy/paste these samples and adapt/use them in production. The motivation for this PR is to use images that:

  • are smaller (x5-10)
  • have less known vulnerabilities

For example, with this Node.js change:

  • Image is x6 smaller (334 → 54.7 MB)
  • There are x7 less detected CVEs (674 → 91)


# Create and change to the app directory.
WORKDIR /usr/src/app
Expand All @@ -14,7 +14,7 @@ COPY package*.json ./
RUN npm install --only=production

# Copy local code to the container image.
COPY . .
COPY . ./
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add the slash after the second period? Is this a syntax preference or do you have a functional goal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a syntax preference.

2 pros

  • All destination folders end with a slash (doc consistency).
  • This will prevent some developers from falling into this dockerfile syntax trap where COPY file1 . works but COPY file1 file2 . fails. Additionally, the sample pattern COPY *.ext . (without /) will eventually bite (only works if there's exactly 1 .ext file). This is used with *.csproj in the C# sample. Using COPY *.ext ./ also prevents this kind of issues from appearing indirectly.

1 con

  • COPY . . looks nicer than COPY . ./.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment in #1732 for the potential issue with COPY *.csproj ..


# Run the web service on container startup.
CMD [ "npm", "start" ]
6 changes: 3 additions & 3 deletions docs/serving/samples/hello-world/helloworld-nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-nodejs
[Dockerizing a Node.js web app](https://nodejs.org/en/docs/guides/nodejs-docker-webapp/).

```Dockerfile
# Use the official Node.js 12 image.
# Use the official lightweight Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12
FROM node:12-slim

# Create and change to the app directory.
WORKDIR /usr/src/app
Expand All @@ -111,7 +111,7 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-nodejs
RUN npm install --only=production

# Copy local code to the container image.
COPY . .
COPY . ./

# Run the web service on container startup.
CMD [ "npm", "start" ]
Expand Down
4 changes: 2 additions & 2 deletions docs/serving/samples/hello-world/helloworld-python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Use the official Python image.
# https://hub.docker.com/_/python
FROM python:3.7
FROM python:3.7-slim

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . .
COPY . ./

# Install production dependencies.
RUN pip install Flask gunicorn
Expand Down
6 changes: 3 additions & 3 deletions docs/serving/samples/hello-world/helloworld-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-python
details.

```docker
# Use the official Python image.
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7
FROM python:3.7-slim

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . .
COPY . ./

# Install production dependencies.
RUN pip install Flask gunicorn
Expand Down
6 changes: 3 additions & 3 deletions docs/serving/samples/hello-world/helloworld-ruby/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Use the official Ruby image.
# Use the official lightweight Ruby image.
# https://hub.docker.com/_/ruby
FROM ruby:2.5
FROM ruby:2.5-slim

# Install production dependencies.
WORKDIR /usr/src/app
Expand All @@ -9,7 +9,7 @@ ENV BUNDLE_FROZEN=true
RUN bundle install

# Copy local code to the container image.
COPY . .
COPY . ./

# Run the web service on container startup.
CMD ["ruby", "./app.rb"]
6 changes: 3 additions & 3 deletions docs/serving/samples/hello-world/helloworld-ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-ruby
details.

```docker
# Use the official Ruby image.
# Use the official lightweight Ruby image.
# https://hub.docker.com/_/ruby
FROM ruby:2.5
FROM ruby:2.5-slim

# Install production dependencies.
WORKDIR /usr/src/app
Expand All @@ -64,7 +64,7 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-ruby
RUN bundle install

# Copy local code to the container image.
COPY . .
COPY . ./

# Run the web service on container startup.
CMD ["ruby", "./app.rb"]
Expand Down