docker_practice/image/dockerfile/onbuild.md

66 lines
4.0 KiB
Go
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 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`