Search code examples
dockercontainersdockerfileamazon-ecs

DOCKER: Executing one-time commands in container after docker run


I am running into a problem with regards to my Dockerfile -- I have a container which contains a web app. Of course, when I start the container, the web app starts and by setting my ENTRYPOINT to '/sbin/init', I can have the container running forever (as in, it doesn't just start up and shutdown).

now, the issue is, I need to do some NFS mounts 'after' the container is started up first time.

I understand I can remove the ENTRYPOINT and utilize CMD to pass in lets say CMD ./my_create_mount_script.sh

but then, how do I make sure my container will keep running just like it was when I was using ENTRYPOINT /sbin/init?

e.g.,

if my 2nd last line in Dockerfile is: CMD ./my_create_mount_script.sh (inside the script are just some mount statements) and my last line is: ENTRYPOINT /sbin/init it won't do me any good as far as I understand because in this case, ENTRYPOINT is expecting CMD to pass it args, nothing else.

^ if it matters, I will deploying this container to AWS ECS


Solution

  • You could pass multiple CMD arguments such as:

    CMD /sbin/init ; /do_something_else
    

    Or you could create a script which does all you want including the starting of the web app and then pass that to your ENTRYPOINT