mirror of
https://github.com/yeasy/docker_practice.git
synced 2025-12-13 09:21:42 +00:00
Use vuepress build book
Signed-off-by: Kang HuaiShuai <khs1994@khs1994.com>
This commit is contained in:
@@ -26,7 +26,7 @@ func main(){
|
||||
|
||||
编写 `Dockerfile.one` 文件
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM golang:1.9-alpine
|
||||
|
||||
RUN apk --no-cache add git ca-certificates
|
||||
@@ -56,7 +56,7 @@ $ docker build -t go/helloworld:1 -f Dockerfile.one .
|
||||
|
||||
例如,编写 `Dockerfile.build` 文件
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM golang:1.9-alpine
|
||||
|
||||
RUN apk --no-cache add git
|
||||
@@ -71,7 +71,7 @@ RUN go get -d -v github.com/go-sql-driver/mysql \
|
||||
|
||||
编写 `Dockerfile.copy` 文件
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk --no-cache add ca-certificates
|
||||
@@ -125,7 +125,7 @@ go/helloworld 1 f55d3e16affc 2 minutes ago 295MB
|
||||
|
||||
例如,编写 `Dockerfile` 文件
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM golang:1.9-alpine as builder
|
||||
|
||||
RUN apk --no-cache add git
|
||||
@@ -172,7 +172,7 @@ go/helloworld 1 f55d3e16affc 2 minutes ago 295MB
|
||||
|
||||
我们可以使用 `as` 来为某一阶段命名,例如
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM golang:1.9-alpine as builder
|
||||
```
|
||||
|
||||
@@ -186,6 +186,6 @@ $ docker build --target builder -t username/imagename:tag .
|
||||
|
||||
上面例子中我们使用 `COPY --from=0 /go/src/github.com/go/helloworld/app .` 从上一阶段的镜像中复制文件,我们也可以复制任意镜像中的文件。
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
$ COPY --from=nginx:latest /etc/nginx/nginx.conf /nginx.conf
|
||||
```
|
||||
|
||||
@@ -50,7 +50,7 @@ server {
|
||||
|
||||
第一阶段进行前端构建。
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM node:alpine as frontend
|
||||
|
||||
COPY package.json /app/
|
||||
@@ -69,7 +69,7 @@ RUN cd /app \
|
||||
|
||||
第二阶段安装 Composer 依赖。
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM composer as composer
|
||||
|
||||
COPY database/ /app/database/
|
||||
@@ -89,7 +89,7 @@ RUN cd /app \
|
||||
|
||||
第三阶段对以上阶段生成的文件进行整合。
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM php:7.2-fpm-alpine as laravel
|
||||
|
||||
ARG LARAVEL_PATH=/app/laravel
|
||||
@@ -113,7 +113,7 @@ RUN cd ${LARAVEL_PATH} \
|
||||
|
||||
### 最后一个阶段构建 NGINX 镜像
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM nginx:alpine as nginx
|
||||
|
||||
ARG LARAVEL_PATH=/app/laravel
|
||||
@@ -164,7 +164,7 @@ $ docker run -it --rm --network=laravel -p 8080:80 my/nginx
|
||||
|
||||
完整的 `Dockerfile` 文件如下。
|
||||
|
||||
```dockerfile
|
||||
```docker
|
||||
FROM node:alpine as frontend
|
||||
|
||||
COPY package.json /app/
|
||||
|
||||
Reference in New Issue
Block a user