The difference between entrypoint and cmd in dockerfile and the role of run

Source: Internet
Author: User
Tags docker run
The difference between entrypoint and cmd

The difference between entrypoint and CMD can refer to the difference between entrypoint and cmd in Dockerfile
The main differences are:
If you use the command-line arguments when you start the container with Docker run, the CMD directive in Dockerfile will be invalid:

Docker run-it Image/bin/ps

After the boot container is found to have no shell, only the process state in the current container is printed out, and the cmd command effect is overwritten:

PID TTY Time CMD
1? 00:00:00 PS
[Root@miwifi-r3l-srv test]#

What to do if you want to pass command-line arguments when you start the container with Docker run. This is the uniqueness of entrypoint.

The command specified by entrypoint needs to be paired with the Docker run boot container, using the contents of the Docker run instruction as parameters to run the command as specified by the entrypoint instruction EntryPoint The specified Linux command is generally not overwritten. the role of Run

The role of run is that sometimes you need to install some software on the underlying image, such as Nginx, when building the image. For example:

From CentOS
Maintainer Allocator
RUN Yum install-y nginx
RUN Echo ' Hello World ' >/usr/share/nginx/html/index.html
EXPOSE 80
entrypoint ["/usr/sbin/nginx"]

The two run above installs the Nginx and writes content to the index.html when the image is built.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.