'How to prevent docker container from stopping after executing sh script file
im running a docker container as shown below, after the sh files are executed the container terminate by default, how i can keep the container working in background
sample from docker file
#=========================
# Copying Scripts to root
#=========================
COPY entry_point.sh \
/root/
RUN chmod +x /root/entry_point.sh
#=======================
# framework entry point
#=======================
CMD /root/entry_point.sh
the entry_point.sh file
function clone_repo() {
mkdir /root/repo
git clone [email protected]:test/tests.git /root/repo && \
rm -rf /root/.ssh
}
clone_repo
and here is the command im using to initialize the container
docker run -p 5900:5900 --name mycontainer--privileged amrka/image
Solution 1:[1]
Solved by removing entry_point
Solution 2:[2]
You could also run CMD /root/entry_point.sh; sleep infinity
Solution 3:[3]
Thats how docker container works, its goes offf when application dies.
Why you need it to keep alive?
What it will do?
if you want just to have, you can run sleep 10000000
for example at end of the file, so it will keep container, but why?
if you want execute any tas on schedule, then you can use any cron image.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Amr Kamel |
Solution 2 | Gloorfindel |
Solution 3 | Giga Kokaia |