docker_practice/image/dockerfile/onbuild.md

66 lines
4.0 KiB
Go
Raw Normal View History

### ONBUILD
`ONBUILD <其它指令>`
`ONBUILD` `RUN`, `COPY`
`Dockerfile` `ONBUILD`
Node.js Node.js 使 `npm` `package.json` `npm install` `npm start` `Dockerfile`
```Dockerfile
FROM node:slim
RUN mkdir /app
WORKDIR /app
COPY ./package.json /app
RUN [ "npm", "install" ]
COPY . /app/
CMD [ "npm", "start" ]
```
`Dockerfile` Node.js Node.js `Dockerfile`
Node.js `Dockerfile` `Dockerfile` `Dockerfile` `Dockerfile` `Dockerfile`
使 `Dockerfile` `Dockerfile`
```Dockerfile
FROM node:slim
RUN mkdir /app
WORKDIR /app
CMD [ "npm", "start" ]
```
`my-node` `Dockerfile`
```Dockerfile
FROM my-node
COPY ./package.json /app
RUN [ "npm", "install" ]
COPY . /app/
```
`Dockerfile`
`Dockerfile` 西 `npm install` `RUN` `./package.json` `Dockerfile` 4
`ONBUILD` `ONBUILD` `Dockerfile`:
```Dockerfile
FROM node:slim
RUN mkdir /app
WORKDIR /app
ONBUILD COPY ./package.json /app
ONBUILD RUN [ "npm", "install" ]
ONBUILD COPY . /app/
CMD [ "npm", "start" ]
```
`Dockerfile` `ONBUILD` `Dockerfile`
```Dockerfile
FROM my-node
```
`Dockerfile` `ONBUILD` `npm install`