Docker basic operation uses --cmd command

Chen Bucheng I 2022-06-24 07:27:07 阅读数:938

dockerbasicoperationusescmd

CMD command

Manual command input is required after the container is started node demos/01.js. We can write this command in Dockerfile Inside , So after the container starts , This command has been executed , No more manual input .

  1. FROM node:8.4
  2. COPY ./app
  3. WORKDIR /app
  4. RUN npm install --registry=https://registry.npm.taobao.org
  5. EXPOSE 3000
  6. CMD node demos/01.js

above Dockerfile Inside , One more line CMD node demos/01.js, It represents automatic execution after the container is started node demos/01.js.

You may ask ,RUN Command and CMD What is the difference between commands ? In short ,RUN Command in image The build phase of the file executes , The execution results will be packaged into image file ;CMD The command is executed after the container is started . in addition , One Dockerfile It can contain more than one RUN command , But there can only be one CMD command .

Be careful , It specifies CMD After the order ,docker container run You can't attach a command to a command ( Like the one in front /bin/bash), Otherwise it will cover CMD command . Now you can start the container using the following command . docker container run --rm -p 8000:3000 -it koa-demo:0.0.1

copyright:author[Chen Bucheng I],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/175/20210702150334473r.html