Docker CMD run bash script in background inside container

I’m trying to run script in background when the container creare (inside container).

I have the following simple start.sh:

f() {
    echo "Sleep"
    sleep 10
    echo "Done"
}

f 

Dockerfile:

FROM alping
COPY start.sh /tmp
CMD /tmp/start.sh &

And after docker run <MY_IMAGE> the docker status is Exited (0)

I’m trying also to change start.sh to:

f() {
    echo "Sleep"
    sleep 10
    echo "Done"
}

f & #Run f function here in background

Dockerfile:

FROM alping
COPY start.sh /tmp
CMD /tmp/start.sh & # Trying also: CMD /bin/sh -c "/tmp/start.sh"

And got the same Exited(0) status.

So how can I run script in background when the container create?

Source: StackOverflow