Solution to the problem that docker CMD/ENTRYPOINT executes the sh script: not found/run.sh:

Solution to the problem that docker CMD/ENTRYPOINT executes the sh script: not found/run.sh:

There is no problem with the Dockerfile configuration, why does an error occur when executing the ENTRYPOINT command?

The container exited as soon as it started.

I checked a lot of information and thought about it for a long time before I found the reason.

run.sh is copied to the container by the COPY instruction. However, the local machine is Windows, and the default line break character is \n, so it cannot be executed after being copied.

The solution is simple, just switch the file format to LF.

Supplementary knowledge: When starting a container in docker, the if command in the sh script called by CMD reports an unexpected symbol if[[. Solution

Recently, I wrote an image through Dockerfile. The sh script (start.sh) was called in CMD to start the container. When it was started through docker run, the startup failed. I performed docker logs container ID and found that the error was: Unexpected symbol if [[

I successfully executed start.sh directly in the external Linux system. I entered the container through docker exec and called start.sh in the container without any errors. All the programs that needed to be started in the command were successfully started.

There is no problem in executing the script directly, but an error occurs through docker run, which is puzzling.

The error code segment in start.sh is as follows

if [[ -e /home/dc/testnn-aaa.zip ]];then
 rm -rf /home/testnn-aaa
 unzip -q -o -d /home testnn-aaa.zip
 echo "unzip zip finished" 
else 
 echo "dc zip not exist"
fi

After checking and comparing, because my start.sh also has an if statement before the error statement, but no error is reported, I found that the difference between the two places is that the first if uses a single []. If the code is changed to [], it will succeed. The modification is as follows:

if [ -e /home/dc/testnn-aaa.zip ];then

The above article on solving the problem of docker CMD/ENTRYPOINT executing sh script: not found/run.sh: is all the content that the editor shared with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • The difference between ENTRYPOINT and CMD in Dockerfile
  • Use non-root users to execute script operations in docker containers
  • Docker file storage path, get container startup command operation

<<:  Vue interpretation of responsive principle source code analysis

>>:  HTML is actually the application of learning several important tags

Recommend

IE conditional comments for XHTML

<br />Conditional comments are a feature uni...

How to write configuration files and use MyBatis simply

How to write configuration files and use MyBatis ...

N ways to center elements with CSS

Table of contents Preface Centering inline elemen...

How to query duplicate data in mysql table

INSERT INTO hk_test(username, passwd) VALUES (...

Detailed explanation of the application of CSS Sprite

CSS Sprite, also known as CSS Sprite, is an image...

How Database SQL SELECT Queries Work

As Web developers, although we are not profession...

Two methods to disable form controls in HTML: readonly and disabled

In the process of making web pages, we often use f...

HTML tutorial, HTML default style

html , address , blockquote , body , dd , div , d...

HTML page jump code

Save the following code as the default homepage fi...

Solutions to MySQL batch insert and unique index problems

MySQL batch insert problem When developing a proj...

hr horizontal line style example code

Copy code The code is as follows: <hr style=&q...

Perfect Solution for No rc.local File in Linux

Newer Linux distributions no longer have the rc.l...