Docker正在制作额外的映像

时间:2018-11-16 00:00:27

标签: docker

当我运行docker-compose up -d命令时,它会运行所有很酷的命令,它会创建很多图像,我不知道这是否应该是正常行为,但看起来像这样

Status: Downloaded newer image for node:11.1.0
 ---> 4e4c445311e6
Step 2/8 : RUN mkdir /usr/src/app
 ---> Running in 3b78051548b7
Removing intermediate container 3b78051548b7
 ---> 96e53f58ca4a
Step 3/8 : WORKDIR /usr/src/app
 ---> Running in 6c09aca5e321
Removing intermediate container 6c09aca5e321
 ---> a392a2bdd279
Step 4/8 : ENV PATH /usr/src/app/node_modules/.bin:$PATH
 ---> Running in 9443cc34dc2a
Removing intermediate container 9443cc34dc2a
 ---> 6ba4c2ed0014

如您所见,它每一步都会产生新图像

在这里您可以看到该命令生成的图像列表

somethinghere_somethinghere   latest              4163a2ac78cc        14 minutes ago      1.23GB
<none>                              <none>              2af2d216914a        14 minutes ago      1.23GB
<none>                              <none>              2471e3d94378        15 minutes ago      1.11GB
<none>                              <none>              6ba4c2ed0014        15 minutes ago      894MB
<none>                              <none>              71141d30cec8        15 minutes ago      894MB
<none>                              <none>              a392a2bdd279        15 minutes ago      894MB
<none>                              <none>              96e53f58ca4a        15 minutes ago      894MB

请告诉我我的docker-compose和dockerfile

Dockerfile

# base image
FROM node:11.1.0

# set working directory
RUN mkdir /usr/src/app
WORKDIR /usr/src/app

# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY package.json /usr/src/app/package.json
RUN npm install --silent
RUN npm install react-scripts@1.1.1 -g --silent

# start app
CMD ["npm", "start"]

docker-compose

version: '3.5'

services:

  somethinghere:
    container_name: somethinghere-client
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - '.:/usr/src/app'
      - '/usr/src/app/node_modules'
    ports:
      - '3000:3000'
    environment:
      - NODE_ENV=development

1 个答案:

答案 0 :(得分:1)

这是docker的缓存机制,如果dockerfile中有较小的更改,它们可以帮助系统更快地构建。

如您在构建输出中所见,

Step 2/8 : RUN mkdir /usr/src/app
 ---> Running in 3b78051548b7
Removing intermediate container 3b78051548b7
 ---> 96e53f58ca4a

使用图像96e53f58ca4a创建一个图层。

通常,您无需担心它们,只需使用docker images,您就不会看到它们。

更多阅读here