Dockerfile CMD instruction will exit the container just after running it

后端 未结 5 2315
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 17:46

I want to setup some configuration when my container starts, for this I am using shell scripts. But my container will exits as soon as my scripts ends, I have tried with -d

5条回答
  •  不思量自难忘°
    2020-12-13 18:05

    Finally with some experiments I got my best result as below

    There is nothing wrong with my Dockerfile as below it's correct.

    FROM ubuntu:14.04
    
    ADD shell.sh /usr/local/bin/shell.sh
    
    RUN chmod 777 /usr/local/bin/shell.sh
    
    CMD /usr/local/bin/shell.sh
    

    What I do to get expected result is, I just add one more command(/bin/bash) in my shell script file as below and vola everything works in my best way.

    #!/bin/bash
    
    echo “Hello-docker” > /usr/hello.txt
    
    /bin/bash
    

提交回复
热议问题