search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Table of Contents
Use --entrypoint when docker run to override the default entry of the image
"> Want to keep the original CMD and only change the entrance? Clear ENTRYPOINT with empty string ""
The command is not executed after overwriting? Check exec vs shell mode differences
How to configure it in docker-compose.yml? The corresponding field is entrypoint
Home Operation and Maintenance Docker How to override the default entrypoint in Docker? (Command line)

How to override the default entrypoint in Docker? (Command line)

Mar 14, 2026 am 12:27 AM

--entrypoint can directly overwrite the image ENTRYPOINT, only accepts a single executable path, and the parameters must be placed after the image name; the shell form must be separated by --, such as --entrypoint sh -- -c "cmd"; use "" or [] to clear the entry.

How to override the default entrypoint in Docker? (Command line)

Use --entrypoint when docker run to override the default entry of the image

It takes effect directly without changing the Dockerfile or rebuilding the image. It will completely replace ENTRYPOINT defined in the image, including shell form (such as ["sh", "-c"] ) and exec form.

  • --entrypoint is followed only by an executable file path (such as /bin/bash ) and cannot contain parameters; parameters must be written after the image name
  • If the original image defines ENTRYPOINT in shell form (for example, ENTRYPOINT node app.js ), after overwriting with --entrypoint , the original command will not be automatically appended - you have to fill in the original CMD yourself, otherwise nothing will be executed.
  • Common misoperations: docker run --entrypoint /bin/sh myimage -c "echo hello" - here -c will be used as the parameter after the image name, but /bin/sh does not accept -c by default, and must be explicitly written as /bin/sh -c

Want to keep the original CMD and only change the entrance? Clear ENTRYPOINT with empty string ""

Some images put all the startup logic into ENTRYPOINT , and CMD is just a parameter. At this time, if you don’t want to change the entry, but just want to temporarily skip it and run the command directly, you must first clear the entry and then run the original CMD as a normal command.

  • Execute an interactive shell: docker run --entrypoint "" -it nginx /bin/sh - This bypasses the default startup script of nginx and connects directly to the shell
  • Note: If the image does not define CMD and there is no command after --entrypoint "" , the container will exit immediately (because there is nothing to execute)
  • This technique is particularly fast when debugging init containers or troubleshooting startup failures. It is more trouble-free than entering the container and then ps to check the process link.

The command is not executed after overwriting? Check exec vs shell mode differences

Docker's processing of --entrypoint strictly follows the exec mode: it only recognizes executable paths in the form of arrays and does not parse shell syntax. If you write --entrypoint "sh -c" in the habit, Docker will try to execute a file named "sh -c" (which obviously doesn't exist).

  • The correct way to write it is: --entrypoint sh -- -c "echo hello" -- the first sh is the entry, and everything after the -- separator is passed in as the parameter of sh
  • Another equivalent way of writing: --entrypoint /bin/sh -- -c "echo hello" , a clearer path
  • Error example: --entrypoint "sh -c 'echo hello'" → error executable file not found in $PATH
  • This is inconsistent with the behavior of shell form ENTRYPOINT in docker build and is easy to confuse.

How to configure it in docker-compose.yml? The corresponding field is entrypoint

Not command , not cmd . It is completely equivalent to the CLI's --entrypoint , and the value can be a string or an array.

  • Array writing method (recommended): entrypoint: ["/bin/sh", "-c"] , clear and unambiguous
  • String writing method: entrypoint: "/bin/sh -c" , Docker will split it into an array internally, but it is prone to errors when encountering spaces or quotation marks, so it is not recommended.
  • If you want to clear the entry, write entrypoint: [] (empty array), not null or empty string
  • Note: entrypoint and command are two independent fields in compose. command is equivalent to CMD of the image and will be passed to entrypoint as a parameter.

In actual use, the most common thing that gets stuck is shell string parsing - you think you wrote a command, but in fact Docker looks for it as a file name. Pay attention to executable file not found in the error message. This is basically the problem.

The above is the detailed content of How to override the default entrypoint in Docker? (Command line). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)