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

HTML Tutorial: title attribute and alt attribute

XHTML is the basis of CSS layout. jb51.net has al...

Detailed explanation of three ways to cut catalina.out logs in tomcat

1. Log4j for log segmentation 1) Prepare three pa...

A brief discussion on common operations of MySQL in cmd and python

Environment configuration 1: Install MySQL and ad...

You may need a large-screen digital scrolling effect like this

The large-screen digital scrolling effect comes f...

How to migrate local mysql to server database

We can use the scp command of Linux (scp cannot b...

Install Docker on Centos7 (2020 latest version available, just copy and paste)

Refer to the official documentation here for oper...

JS removeAttribute() method to delete an attribute of an element

In JavaScript, use the removeAttribute() method o...

Vue-Router installation process and principle detailed

Table of contents 1. Front-end routing implementa...

Implementation of CSS equal division of parent container (perfect thirds)

The width of the parent container is fixed. In or...

Good website copywriting and good user experience

Looking at a website is actually like evaluating a...

A complete guide to clearing floats in CSS (summary)

1. Parent div defines pseudo-classes: after and z...

MySQL 8.0 New Features - Introduction to the Use of Management Port

Table of contents Preface Connection Management A...

The process of building lamp architecture through docker container

Table of contents 1. Pull the centos image 2. Bui...

How to create a table by month in MySQL stored procedure

Without going into details, let's go straight...