docker_practice/image/dockerfile/onbuild.md

66 lines
3.9 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`
```docker
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`
```docker
FROM node:slim
RUN mkdir /app
WORKDIR /app
CMD [ "npm", "start" ]
```
`my-node` `Dockerfile`
```docker
FROM my-node
COPY ./package.json /app
RUN [ "npm", "install" ]
COPY . /app/
```
`Dockerfile`
`Dockerfile` 西 `npm install` `RUN` `./package.json` `Dockerfile` 4
`ONBUILD` `ONBUILD` `Dockerfile`:
```docker
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`
```docker
FROM my-node
```
`Dockerfile` `ONBUILD` `npm install`