Home >Operation and Maintenance >Docker >How to solve the problem of docker executing exec error
Solution to the error when docker executes exec: 1. Replace the first line in the script with "/bin/bash"; 2. Execute "docker exec -d service_name /bin/bash -c '/opt /start.sh'".
The operating environment of this article: centos7 system, Docker version 20.10.11, Dell G3 computer.
Docker exec failed to execute script solution
##Background introduction
Original script
docker exec -it service_name /bin/bash -c '/opt/start.sh'The function of this start.sh is to start two services in the background
#!/bash nohup start1.sh > start1.log 2>&1 & sleep 5 nohup start2.sh 2>&1 & echo 'server started'
Problem location
1. Irregular script writing
From the above command, you can see the formula used when docker is started/bin/bash And the script What is specified in is indeed
/bash. We all know that the content of the first line of the script specifies the path of the shell script interpreter, and this specified path can only be placed on the first line of the file. Therefore, you need to replace the first line in the script with
/bin/bash so that they use the same interpreter
2. There is a problem with the startup parameters
The-it parameter is used during the execution of docker exec.
docker exec -d service_name /bin/bash -c '/opt/start.sh'
#!/bin/bash nohup start1.sh > start1.log 2>&1 & sleep 5 nohup start2.sh 2>&1 & echo 'server started'
docker tutorial"
The above is the detailed content of How to solve the problem of docker executing exec error. For more information, please follow other related articles on the PHP Chinese website!