From dd5d7bff0bfdc4af87fc2c45afbb1b61b32b228c Mon Sep 17 00:00:00 2001 From: sid palas Date: Wed, 25 Jan 2023 17:55:51 -0500 Subject: [PATCH] Add incremental dockerfiles --- .../sample-app/api-golang/.dockerignore | 3 ++ .../sample-app/api-golang/Dockerfile | 19 -------- .../sample-app/api-golang/Dockerfile.0 | 9 ++++ .../sample-app/api-golang/Dockerfile.1 | 11 +++++ .../sample-app/api-golang/Dockerfile.2 | 14 ++++++ .../sample-app/api-golang/Dockerfile.3 | 17 +++++++ .../sample-app/api-golang/Dockerfile.4 | 29 ++++++++++++ .../sample-app/api-golang/Dockerfile.5 | 35 ++++++++++++++ .../sample-app/api-golang/Dockerfile.6 | 47 +++++++++++++++++++ .../sample-app/api-golang/Makefile | 4 +- .../sample-app/api-node/Dockerfile | 19 -------- .../sample-app/api-node/Dockerfile.0 | 7 +++ .../sample-app/api-node/Dockerfile.1 | 9 ++++ .../sample-app/api-node/Dockerfile.2 | 12 +++++ .../sample-app/api-node/Dockerfile.3 | 18 +++++++ .../sample-app/api-node/Dockerfile.4 | 22 +++++++++ .../sample-app/api-node/Dockerfile.5 | 26 ++++++++++ .../sample-app/api-node/Dockerfile.6 | 29 ++++++++++++ .../sample-app/api-node/Dockerfile.7 | 36 ++++++++++++++ .../sample-app/api-node/Makefile | 6 ++- .../sample-app/api-node/src/index.js | 9 +++- .../sample-app/client-react/Dockerfile.0 | 7 +++ .../sample-app/client-react/Dockerfile.1 | 7 +++ .../sample-app/client-react/Dockerfile.2 | 14 ++++++ .../sample-app/client-react/Dockerfile.3 | 24 ++++++++++ .../sample-app/client-react/nginx.conf | 24 ++++++++++ .../sample-app/client-react/src/App.jsx | 4 +- .../sample-app/docker-compose.yml | 18 +++++-- .../sample-dockerfiles/Dockerfile | 37 +++++++++++++++ 29 files changed, 467 insertions(+), 49 deletions(-) create mode 100644 04-building-container-images/sample-app/api-golang/.dockerignore delete mode 100644 04-building-container-images/sample-app/api-golang/Dockerfile create mode 100644 04-building-container-images/sample-app/api-golang/Dockerfile.0 create mode 100644 04-building-container-images/sample-app/api-golang/Dockerfile.1 create mode 100644 04-building-container-images/sample-app/api-golang/Dockerfile.2 create mode 100644 04-building-container-images/sample-app/api-golang/Dockerfile.3 create mode 100644 04-building-container-images/sample-app/api-golang/Dockerfile.4 create mode 100644 04-building-container-images/sample-app/api-golang/Dockerfile.5 create mode 100644 04-building-container-images/sample-app/api-golang/Dockerfile.6 delete mode 100644 04-building-container-images/sample-app/api-node/Dockerfile create mode 100644 04-building-container-images/sample-app/api-node/Dockerfile.0 create mode 100644 04-building-container-images/sample-app/api-node/Dockerfile.1 create mode 100644 04-building-container-images/sample-app/api-node/Dockerfile.2 create mode 100644 04-building-container-images/sample-app/api-node/Dockerfile.3 create mode 100644 04-building-container-images/sample-app/api-node/Dockerfile.4 create mode 100644 04-building-container-images/sample-app/api-node/Dockerfile.5 create mode 100644 04-building-container-images/sample-app/api-node/Dockerfile.6 create mode 100644 04-building-container-images/sample-app/api-node/Dockerfile.7 create mode 100644 04-building-container-images/sample-app/client-react/Dockerfile.0 create mode 100644 04-building-container-images/sample-app/client-react/Dockerfile.1 create mode 100644 04-building-container-images/sample-app/client-react/Dockerfile.2 create mode 100644 04-building-container-images/sample-app/client-react/Dockerfile.3 create mode 100644 04-building-container-images/sample-app/client-react/nginx.conf create mode 100644 04-building-container-images/sample-dockerfiles/Dockerfile diff --git a/04-building-container-images/sample-app/api-golang/.dockerignore b/04-building-container-images/sample-app/api-golang/.dockerignore new file mode 100644 index 0000000..bbda771 --- /dev/null +++ b/04-building-container-images/sample-app/api-golang/.dockerignore @@ -0,0 +1,3 @@ +Makefile +README.md +Dockerfile* \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-golang/Dockerfile b/04-building-container-images/sample-app/api-golang/Dockerfile deleted file mode 100644 index 9b87b28..0000000 --- a/04-building-container-images/sample-app/api-golang/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -# syntax=docker/dockerfile:1 - -# Alpine is chosen for its small footprint -# compared to Ubuntu -FROM golang:1.19-alpine - -WORKDIR /app - -# Download necessary Go modules -COPY go.mod ./ -COPY go.sum ./ - -RUN go mod download - -COPY . . - -CMD ["go", "run", "./main.go"] - -# TODO use best practices: https://snyk.io/blog/containerizing-go-applications-with-docker/ \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-golang/Dockerfile.0 b/04-building-container-images/sample-app/api-golang/Dockerfile.0 new file mode 100644 index 0000000..910e5c9 --- /dev/null +++ b/04-building-container-images/sample-app/api-golang/Dockerfile.0 @@ -0,0 +1,9 @@ +FROM golang + +WORKDIR /app + +COPY . . + +RUN go mod download + +CMD ["go", "run", "./main.go"] diff --git a/04-building-container-images/sample-app/api-golang/Dockerfile.1 b/04-building-container-images/sample-app/api-golang/Dockerfile.1 new file mode 100644 index 0000000..78b7084 --- /dev/null +++ b/04-building-container-images/sample-app/api-golang/Dockerfile.1 @@ -0,0 +1,11 @@ +# Pin specific version for stability +# Use alpine for reduced image size +FROM golang:1.19-alpine + +WORKDIR /app + +COPY . . + +RUN go mod download + +CMD ["go", "run", "./main.go"] diff --git a/04-building-container-images/sample-app/api-golang/Dockerfile.2 b/04-building-container-images/sample-app/api-golang/Dockerfile.2 new file mode 100644 index 0000000..7d0caee --- /dev/null +++ b/04-building-container-images/sample-app/api-golang/Dockerfile.2 @@ -0,0 +1,14 @@ +# Pin specific version for stability +# Use alpine for reduced image size +FROM golang:1.19-alpine + +WORKDIR /app + +COPY . . + +RUN go mod download + +# Compile application during build rather than at runtime +RUN go build -o api-golang + +CMD ["./api-golang"] diff --git a/04-building-container-images/sample-app/api-golang/Dockerfile.3 b/04-building-container-images/sample-app/api-golang/Dockerfile.3 new file mode 100644 index 0000000..a8a840c --- /dev/null +++ b/04-building-container-images/sample-app/api-golang/Dockerfile.3 @@ -0,0 +1,17 @@ +# Pin specific version for stability +# Use alpine for reduced image size +FROM golang:1.19-alpine + +WORKDIR /app + +# Copy only files required to install dependencies (better layer caching) +COPY go.mod go.sum ./ + +RUN go mod download + +COPY . . + +# Compile application during build rather than at runtime +RUN go build -o api-golang + +CMD ["./api-golang"] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-golang/Dockerfile.4 b/04-building-container-images/sample-app/api-golang/Dockerfile.4 new file mode 100644 index 0000000..cfea973 --- /dev/null +++ b/04-building-container-images/sample-app/api-golang/Dockerfile.4 @@ -0,0 +1,29 @@ +# Pin specific version for stability +# Use separate stage for building image +# Use debian for easier build utilities +FROM golang:1.19-bullseye AS build + +WORKDIR /app + +# Copy only files required to install dependencies (better layer caching) +COPY go.mod go.sum ./ + +RUN go mod download + +COPY . . + +# Compile application during build rather than at runtime +# Add -w and -s flags to +RUN go build \ + -ldflags="-linkmode external -extldflags -static" \ + -o api-golang + +# Use separate stage for deployable image +FROM scratch + +WORKDIR / + +# Copy the binary from the build stage +COPY --from=build /app/api-golang api-golang + +CMD ["/api-golang"] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-golang/Dockerfile.5 b/04-building-container-images/sample-app/api-golang/Dockerfile.5 new file mode 100644 index 0000000..b882921 --- /dev/null +++ b/04-building-container-images/sample-app/api-golang/Dockerfile.5 @@ -0,0 +1,35 @@ +# Pin specific version for stability +# Use separate stage for building image +# Use debian for easier build utilities +FROM golang:1.19-bullseye AS build + +WORKDIR /app + +# Copy only files required to install dependencies (better layer caching) +COPY go.mod go.sum ./ + +RUN go mod download + +COPY . . + +# Compile application during build rather than at runtime +# Add flags to statically link binary +RUN go build \ + -ldflags="-linkmode external -extldflags -static" \ + -o api-golang + +# Use separate stage for deployable image +FROM scratch + +# Set gin mode +ENV GIN_MODE=release + +WORKDIR / + +# Copy the binary from the build stage +COPY --from=build /app/api-golang api-golang + +# Indicate expected port +EXPOSE 8080 + +CMD ["/api-golang"] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-golang/Dockerfile.6 b/04-building-container-images/sample-app/api-golang/Dockerfile.6 new file mode 100644 index 0000000..13e2efb --- /dev/null +++ b/04-building-container-images/sample-app/api-golang/Dockerfile.6 @@ -0,0 +1,47 @@ +# Pin specific version for stability +# Use separate stage for building image +# Use debian for easier build utilities +FROM golang:1.19-bullseye AS build + +# Add non root user +RUN useradd -u 1001 nonroot + +WORKDIR /app + +# Copy only files required to install dependencies (better layer caching) +COPY go.mod go.sum ./ + +# Use cache mount to speed up install of existing dependencies +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go mod download + +COPY . . + +# Compile application during build rather than at runtime +# Add flags to statically link binary +RUN go build \ + -ldflags="-linkmode external -extldflags -static" \ + -o api-golang + +# Use separate stage for deployable image +FROM scratch + +# Set gin mode +ENV GIN_MODE=release + +WORKDIR / + +# Copy the passwd file +COPY --from=build /etc/passwd /etc/passwd + +# Copy the binary from the build stage +COPY --from=build /app/api-golang api-golang + +# Use nonroot user +USER nonroot + +# Indicate expected port +EXPOSE 8080 + +CMD ["/api-golang"] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-golang/Makefile b/04-building-container-images/sample-app/api-golang/Makefile index 87ca1c9..f3c1a9f 100644 --- a/04-building-container-images/sample-app/api-golang/Makefile +++ b/04-building-container-images/sample-app/api-golang/Makefile @@ -1,4 +1,4 @@ .PHONY: run-local run-local: - DATABASE_URL=postgres://postgres:foobarbaz@localhost:5432/postgres \ - go run main.go \ No newline at end of file + DATABASE_URL=postgres://postgres:foobarbaz@localhost:5432/postgres \ + go run main.go diff --git a/04-building-container-images/sample-app/api-node/Dockerfile b/04-building-container-images/sample-app/api-node/Dockerfile deleted file mode 100644 index 33c5371..0000000 --- a/04-building-container-images/sample-app/api-node/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM node:19.4-alpine - -# Create app directory -WORKDIR /usr/src/app - -# Install app dependencies -# A wildcard is used to ensure both package.json AND package-lock.json are copied -# where available (npm@5+) -COPY package*.json ./ - -RUN npm install -# If you are building your code for production -# RUN npm ci --only=production - -# Bundle app source -COPY ./src/ . - -EXPOSE 3000 -CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-node/Dockerfile.0 b/04-building-container-images/sample-app/api-node/Dockerfile.0 new file mode 100644 index 0000000..7667bfc --- /dev/null +++ b/04-building-container-images/sample-app/api-node/Dockerfile.0 @@ -0,0 +1,7 @@ +FROM node + +COPY . . + +RUN npm install + +CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-node/Dockerfile.1 b/04-building-container-images/sample-app/api-node/Dockerfile.1 new file mode 100644 index 0000000..7e3d153 --- /dev/null +++ b/04-building-container-images/sample-app/api-node/Dockerfile.1 @@ -0,0 +1,9 @@ +# Pin specific version +# Use alpine for reduced image size +FROM node:19.4-alpine + +COPY . . + +RUN npm install + +CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-node/Dockerfile.2 b/04-building-container-images/sample-app/api-node/Dockerfile.2 new file mode 100644 index 0000000..e9e76ec --- /dev/null +++ b/04-building-container-images/sample-app/api-node/Dockerfile.2 @@ -0,0 +1,12 @@ +# Pin specific version +# Use alpine for reduced image size +FROM node:19.4-alpine + +# Specify working directory other than / +WORKDIR /usr/src/app + +COPY . . + +RUN npm install + +CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-node/Dockerfile.3 b/04-building-container-images/sample-app/api-node/Dockerfile.3 new file mode 100644 index 0000000..69e1023 --- /dev/null +++ b/04-building-container-images/sample-app/api-node/Dockerfile.3 @@ -0,0 +1,18 @@ +# Pin specific version for stability +# Use alpine for reduced image size +FROM node:19.4-alpine + +# Specify working directory other than / +WORKDIR /usr/src/app + +# Copy only files required to install +# dependencies (better layer caching) +COPY package*.json ./ + +RUN npm install + +# Copy remaining source code AFTER installing dependencies. +# Again, copy only the necessary files +COPY ./src/ . + +CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-node/Dockerfile.4 b/04-building-container-images/sample-app/api-node/Dockerfile.4 new file mode 100644 index 0000000..2744cec --- /dev/null +++ b/04-building-container-images/sample-app/api-node/Dockerfile.4 @@ -0,0 +1,22 @@ +# Pin specific version for stability +# Use alpine for reduced image size +FROM node:19.4-alpine + +# Specify working directory other than / +WORKDIR /usr/src/app + +# Copy only files required to install +# dependencies (better layer caching) +COPY package*.json ./ + +RUN npm install + +# Use non-root user +# Use --chown on COPY commands to set file permissions +USER node + +# Copy remaining source code AFTER installing dependencies. +# Again, copy only the necessary files +COPY --chown=node:node ./src/ . + +CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-node/Dockerfile.5 b/04-building-container-images/sample-app/api-node/Dockerfile.5 new file mode 100644 index 0000000..c1eb61d --- /dev/null +++ b/04-building-container-images/sample-app/api-node/Dockerfile.5 @@ -0,0 +1,26 @@ +# Pin specific version for stability +# Use alpine for reduced image size +FROM node:19.4-alpine + +# Set NODE_ENV +ENV NODE_ENV production + +# Specify working directory other than / +WORKDIR /usr/src/app + +# Copy only files required to install +# dependencies (better layer caching) +COPY package*.json ./ + +# Install only production dependencies +RUN npm ci --only=production + +# Use non-root user +# Use --chown on COPY commands to set file permissions +USER node + +# Copy remaining source code AFTER installing dependencies. +# Again, copy only the necessary files +COPY --chown=node:node ./src/ . + +CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-node/Dockerfile.6 b/04-building-container-images/sample-app/api-node/Dockerfile.6 new file mode 100644 index 0000000..6c71c95 --- /dev/null +++ b/04-building-container-images/sample-app/api-node/Dockerfile.6 @@ -0,0 +1,29 @@ +# Pin specific version for stability +# Use alpine for reduced image size +FROM node:19.4-alpine + +# Set NODE_ENV +ENV NODE_ENV production + +# Specify working directory other than / +WORKDIR /usr/src/app + +# Copy only files required to install +# dependencies (better layer caching) +COPY package*.json ./ + +# Install only production dependencies +RUN npm ci --only=production + +# Use non-root user +# Use --chown on COPY commands to set file permissions +USER node + +# Copy remaining source code AFTER installing dependencies. +# Again, copy only the necessary files +COPY --chown=node:node ./src/ . + +# Indicate expected port +EXPOSE 3000 + +CMD [ "node", "index.js" ] \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-node/Dockerfile.7 b/04-building-container-images/sample-app/api-node/Dockerfile.7 new file mode 100644 index 0000000..47dae87 --- /dev/null +++ b/04-building-container-images/sample-app/api-node/Dockerfile.7 @@ -0,0 +1,36 @@ +# Pin specific version for stability +# Use alpine for reduced image size +FROM node:19.4-alpine + +# Set NODE_ENV +ENV NODE_ENV production + +# Specify working directory other than / +WORKDIR /usr/src/app + +# Copy only files required to install +# dependencies (better layer caching) +COPY package*.json ./ + +# Install only production dependencies +# Use cache mount to speed up install of existing dependencies +RUN --mount=type=cache,target=/usr/src/app/.npm \ + npm set cache /usr/src/app/.npm && \ + npm ci --only=production + +# Use non-root user +# Use --chown on COPY commands to set file permissions +USER node + +# Copy remaining source code AFTER installing dependencies. +# Again, copy only the necessary files +COPY --chown=node:node ./src/ . + +# Indicate expected port +EXPOSE 3000 + +CMD [ "node", "index.js" ] + +# TODO: Use multi-stage with distroless image or chainguard image? +# https://github.com/GoogleContainerTools/distroless/blob/main/examples/nodejs/Dockerfile +# https://edu.chainguard.dev/chainguard/chainguard-images/reference/node/overview/ \ No newline at end of file diff --git a/04-building-container-images/sample-app/api-node/Makefile b/04-building-container-images/sample-app/api-node/Makefile index f43e212..dfeef82 100644 --- a/04-building-container-images/sample-app/api-node/Makefile +++ b/04-building-container-images/sample-app/api-node/Makefile @@ -5,4 +5,8 @@ run-local: PGPASSWORD=foobarbaz \ PGDATABASE=postgres \ PGPORT=5432 \ - node ./src/index.js \ No newline at end of file + node ./src/index.js + +.PHONY: build-naive +build-naive: + docker build --file ./Dockerfile.naive . diff --git a/04-building-container-images/sample-app/api-node/src/index.js b/04-building-container-images/sample-app/api-node/src/index.js index c2f28f5..d88829f 100644 --- a/04-building-container-images/sample-app/api-node/src/index.js +++ b/04-building-container-images/sample-app/api-node/src/index.js @@ -12,6 +12,13 @@ app.get('/', async (req, res) => { res.send(response); }); -app.listen(port, () => { +const server = app.listen(port, () => { console.log(`Example app listening on port ${port}`); }); + +process.on('SIGTERM', () => { + debug('SIGTERM signal received: closing HTTP server'); + server.close(() => { + debug('HTTP server closed'); + }); +}); diff --git a/04-building-container-images/sample-app/client-react/Dockerfile.0 b/04-building-container-images/sample-app/client-react/Dockerfile.0 new file mode 100644 index 0000000..e80881b --- /dev/null +++ b/04-building-container-images/sample-app/client-react/Dockerfile.0 @@ -0,0 +1,7 @@ +FROM node + +COPY . . + +RUN npm install + +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/04-building-container-images/sample-app/client-react/Dockerfile.1 b/04-building-container-images/sample-app/client-react/Dockerfile.1 new file mode 100644 index 0000000..6600698 --- /dev/null +++ b/04-building-container-images/sample-app/client-react/Dockerfile.1 @@ -0,0 +1,7 @@ +FROM node:19.4-bullseye + +COPY . . + +RUN npm install + +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/04-building-container-images/sample-app/client-react/Dockerfile.2 b/04-building-container-images/sample-app/client-react/Dockerfile.2 new file mode 100644 index 0000000..6d535fe --- /dev/null +++ b/04-building-container-images/sample-app/client-react/Dockerfile.2 @@ -0,0 +1,14 @@ +FROM node:19.4-bullseye AS build + +# Specify working directory other than / +WORKDIR /usr/src/app + +# Copy only files required to install +# dependencies (better layer caching) +COPY package*.json ./ + +RUN npm install + +COPY . . + +CMD ["npm", "run", "dev"] \ No newline at end of file diff --git a/04-building-container-images/sample-app/client-react/Dockerfile.3 b/04-building-container-images/sample-app/client-react/Dockerfile.3 new file mode 100644 index 0000000..9385af0 --- /dev/null +++ b/04-building-container-images/sample-app/client-react/Dockerfile.3 @@ -0,0 +1,24 @@ +FROM node:19.4-bullseye AS build + +# Specify working directory other than / +WORKDIR /usr/src/app + +# Copy only files required to install +# dependencies (better layer caching) +COPY package*.json ./ + +# Use cache mount to speed up install of existing dependencies +RUN --mount=type=cache,target=/usr/src/app/.npm \ + npm set cache /usr/src/app/.npm && \ + npm install + +COPY . . + +RUN npm run build + +# Use separate stage for deployable image +FROM nginx:1.23-alpine + +COPY nginx.conf /etc/nginx/conf.d/default.conf + +COPY --from=build usr/src/app/dist/ /usr/share/nginx/html diff --git a/04-building-container-images/sample-app/client-react/nginx.conf b/04-building-container-images/sample-app/client-react/nginx.conf new file mode 100644 index 0000000..5d0c2c6 --- /dev/null +++ b/04-building-container-images/sample-app/client-react/nginx.conf @@ -0,0 +1,24 @@ +server { + listen 80; + location /api/golang/ { + resolver 127.0.0.1; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://api-golang:8080/; + } + location /api/node/ { + resolver 127.0.0.1; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Server $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://api-node:3000/; + } + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html =404; + } + + include /etc/nginx/extra-conf.d/*.conf; +} \ No newline at end of file diff --git a/04-building-container-images/sample-app/client-react/src/App.jsx b/04-building-container-images/sample-app/client-react/src/App.jsx index c5fb1ed..f8fa732 100644 --- a/04-building-container-images/sample-app/client-react/src/App.jsx +++ b/04-building-container-images/sample-app/client-react/src/App.jsx @@ -37,8 +37,8 @@ export function App() { return (

Hey Team! 👋

- - + +
); } diff --git a/04-building-container-images/sample-app/docker-compose.yml b/04-building-container-images/sample-app/docker-compose.yml index 36ec6b5..b6de7a4 100644 --- a/04-building-container-images/sample-app/docker-compose.yml +++ b/04-building-container-images/sample-app/docker-compose.yml @@ -2,15 +2,21 @@ services: client-react: build: context: ./client-react - # Could remove... - depends_on: - - api-node - - api-golang + dockerfile: Dockerfile ports: - 5173:5173 + client-react-nginx: + build: + context: ./client-react + dockerfile: Dockerfile.3 + init: true + ports: + - 5174:80 api-node: build: context: ./api-node + dockerfile: Dockerfile.7 + init: true depends_on: - db environment: @@ -24,6 +30,8 @@ services: api-golang: build: context: ./api-golang + dockerfile: Dockerfile.6 + init: true depends_on: - db environment: @@ -35,4 +43,4 @@ services: environment: - POSTGRES_PASSWORD=foobarbaz ports: - - 5432:5432 \ No newline at end of file + - 5432:5432 diff --git a/04-building-container-images/sample-dockerfiles/Dockerfile b/04-building-container-images/sample-dockerfiles/Dockerfile new file mode 100644 index 0000000..54d5cd5 --- /dev/null +++ b/04-building-container-images/sample-dockerfiles/Dockerfile @@ -0,0 +1,37 @@ +# syntax=docker/dockerfile:1 +# escape=\ +# ^ OPTIONAL "directives" (must be at top if used) + +# THIS IS A COMMENT + +# ARG is the only instruction that can come before FROM +ARG BASE_IMAGE_TAG=19.4 +# ARGs can be overriden at build time +# > docker build --build-arg BASE_VERSION=19.3 . + +FROM node:${BASE_IMAGE_TAG} + +RUN echo "Hey Team 👋 (shell form)" +RUN ["echo", "Hey Team 👋 (exec form)"] + +# --mount allows for mounting additional files +# into the build context +# RUN --mount=type=bind ... +# RUN --mount=type=cache ... +# RUN --mount=type=secret ... +# RUN --mount=type=ssh ... + +# Available only at build time +# (Still in image metadata though...) +ARG BUILD_ARG=foo + +# Available at build and run time +ENV ENV_VAR=bar + +# Set the default working directory +# Use the convention of your language/framework +WORKDIR path/to/the/working/directory + + +ENTRYPOINT [ "echo", "Hey Team 👋 (entrypoint)" ] +CMD [ "+ (cmd)" ] \ No newline at end of file