EntryPoints
Entrypoints are what operation we take when start a container.
Set entrypoint from terminal
cmd
docker run <container> <cmd>
docker run vue-app npm run serve
entrypoint
docker run <container> --entrypoint <cmd>
docker run vue-app --entrypoint npm run serve
Set entrypoint using CMD
in dockerfile
Two syntax CMD
supports shell form
and exec form
.
shell form
dockerfile
FROM node:alpine
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
COPY . .
RUN npm install
ENV API_URL=http://api.myapp.com
EXPOSE 8080
CMD npm start
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
exec form
dockerfile
FROM node:alpine
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
COPY . .
RUN npm install
ENV API_URL=http://api.myapp.com
EXPOSE 8080
CMD ["npm", "run", "serve"]
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
prefer exec form
the shell form
starts a new terminal process when executing, while exec form
does not, so in common practice we prefer exec form
.
Using ENTRYPOINT
in dockerfile
The difference between ENTRYPOINT
and CMD
is, CMD
can be override when we specify the command for running container.
docker run vue-app echo hello
, and the npm run serve
specified by CMD
is ignored.
However, command specified by ENTRYPOINT
will absolutely execute when launch. So make sure you really need this for your project.
dockerfile
FROM node:alpine
WORKDIR /app
COPY . .
RUN apk upgrade
RUN npm install
RUN addgroup app && adduser -S -G app app
USER app
ENV API_URL=http://api.myapp.com
EXPOSE 8080
ENTRYPOINT ["npm", "run", "serve"]
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10