mirror of
https://github.com/yeasy/docker_practice.git
synced 2026-03-10 11:54:37 +00:00
Release v1.5.0: Restructure chapters and update for Docker v30.x
This commit is contained in:
16
04_image/demo/buildkit/Dockerfile
Normal file
16
04_image/demo/buildkit/Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
||||
FROM node:alpine as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json /app/
|
||||
|
||||
RUN npm i --registry=https://registry.npmmirror.com \
|
||||
&& rm -rf ~/.npm
|
||||
|
||||
COPY src /app/src
|
||||
|
||||
RUN npm run build
|
||||
|
||||
FROM nginx:alpine
|
||||
|
||||
COPY --from=builder /app/dist /app/dist
|
||||
37
04_image/demo/buildkit/Dockerfile.buildkit
Normal file
37
04_image/demo/buildkit/Dockerfile.buildkit
Normal file
@@ -0,0 +1,37 @@
|
||||
# syntax = docker/dockerfile:experimental
|
||||
|
||||
FROM node:alpine as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json /app/
|
||||
|
||||
RUN --mount=type=cache,target=/app/node_modules,id=my_app_npm_module,sharing=locked \
|
||||
--mount=type=cache,target=/root/.npm,id=npm_cache \
|
||||
npm i --registry=https://registry.npmmirror.com
|
||||
|
||||
COPY src /app/src
|
||||
|
||||
RUN --mount=type=cache,target=/app/node_modules,id=my_app_npm_module,sharing=locked \
|
||||
# --mount=type=cache,target=/app/dist,id=my_app_dist,sharing=locked \
|
||||
npm run build
|
||||
|
||||
FROM nginx:alpine
|
||||
|
||||
# COPY --from=builder /app/dist /app/dist
|
||||
|
||||
# 为了更直观的说明 from 和 source 指令,这里使用 RUN 指令
|
||||
RUN --mount=type=cache,target=/tmp/dist,from=builder,source=/app/dist \
|
||||
# --mount=type=cache,target/tmp/dist,from=my_app_dist,sharing=locked \
|
||||
mkdir -p /app/dist && cp -r /tmp/dist/* /app/dist
|
||||
|
||||
RUN --mount=type=bind,from=php:alpine,source=/usr/local/bin/docker-php-entrypoint,target=/docker-php-entrypoint \
|
||||
cat /docker-php-entrypoint
|
||||
|
||||
RUN --mount=type=tmpfs,target=/temp \
|
||||
mount | grep /temp
|
||||
|
||||
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
|
||||
cat /root/.aws/credentials
|
||||
|
||||
# docker build -t test --secret id=aws,src=$PWD/aws.txt --progress=plain -f Dockerfile.buildkit .
|
||||
1
04_image/demo/buildkit/aws.txt
Normal file
1
04_image/demo/buildkit/aws.txt
Normal file
@@ -0,0 +1 @@
|
||||
awskey
|
||||
11
04_image/demo/buildkit/package.json
Normal file
11
04_image/demo/buildkit/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "my_app",
|
||||
"version": "19.6.0",
|
||||
"devDependencies": {
|
||||
"webpack": "*",
|
||||
"webpack-cli": "*"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "mkdir -p $PWD/dist && cp -r src/* dist/"
|
||||
}
|
||||
}
|
||||
1
04_image/demo/buildkit/src/index.js
Normal file
1
04_image/demo/buildkit/src/index.js
Normal file
@@ -0,0 +1 @@
|
||||
console.log(1);
|
||||
5
04_image/demo/multi-arch/Dockerfile
Normal file
5
04_image/demo/multi-arch/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM --platform=$TARGETPLATFORM alpine
|
||||
|
||||
RUN uname -a > /os.txt
|
||||
|
||||
CMD cat /os.txt
|
||||
1
04_image/demo/multistage-builds/.gitignore
vendored
Normal file
1
04_image/demo/multistage-builds/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
app
|
||||
21
04_image/demo/multistage-builds/Dockerfile
Normal file
21
04_image/demo/multistage-builds/Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
||||
FROM golang:alpine as builder
|
||||
|
||||
RUN apk --no-cache add git
|
||||
|
||||
WORKDIR /go/src/github.com/go/helloworld/
|
||||
|
||||
RUN go get -d -v github.com/go-sql-driver/mysql
|
||||
|
||||
COPY app.go .
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
|
||||
|
||||
FROM alpine:latest as prod
|
||||
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
COPY --from=0 /go/src/github.com/go/helloworld/app .
|
||||
|
||||
CMD ["./app"]
|
||||
10
04_image/demo/multistage-builds/Dockerfile.build
Normal file
10
04_image/demo/multistage-builds/Dockerfile.build
Normal file
@@ -0,0 +1,10 @@
|
||||
FROM golang:alpine
|
||||
|
||||
RUN apk --no-cache add git
|
||||
|
||||
WORKDIR /go/src/github.com/go/helloworld
|
||||
|
||||
COPY app.go .
|
||||
|
||||
RUN go get -d -v github.com/go-sql-driver/mysql \
|
||||
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
|
||||
9
04_image/demo/multistage-builds/Dockerfile.copy
Normal file
9
04_image/demo/multistage-builds/Dockerfile.copy
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk --no-cache add ca-certificates
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
COPY app .
|
||||
|
||||
CMD ["./app"]
|
||||
15
04_image/demo/multistage-builds/Dockerfile.one
Normal file
15
04_image/demo/multistage-builds/Dockerfile.one
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM golang:alpine
|
||||
|
||||
RUN apk --no-cache add git ca-certificates
|
||||
|
||||
WORKDIR /go/src/github.com/go/helloworld/
|
||||
|
||||
COPY app.go .
|
||||
|
||||
RUN go get -d -v github.com/go-sql-driver/mysql \
|
||||
&& CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . \
|
||||
&& cp /go/src/github.com/go/helloworld/app /root
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
CMD ["./app"]
|
||||
7
04_image/demo/multistage-builds/app.go
Normal file
7
04_image/demo/multistage-builds/app.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main(){
|
||||
fmt.Printf("Hello World!");
|
||||
}
|
||||
14
04_image/demo/multistage-builds/build.sh
Normal file
14
04_image/demo/multistage-builds/build.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo Building go/helloworld:build
|
||||
|
||||
docker build -t go/helloworld:build . -f Dockerfile.build
|
||||
|
||||
docker create --name extract go/helloworld:build
|
||||
docker cp extract:/go/src/github.com/go/helloworld/app ./app
|
||||
docker rm -f extract
|
||||
|
||||
echo Building go/helloworld:2
|
||||
|
||||
docker build --no-cache -t go/helloworld:2 . -f Dockerfile.copy
|
||||
rm ./app
|
||||
Reference in New Issue
Block a user