I modified the ubuntu official image and installed apache2 and laravel and then commited it. Every time I try to run the image it fails (exited 0 and 127, depends of what CMD command I run on commit), I can’t get it to start neither. This is my second try, after I already tried using Dockerfiles. The only problem with Dockerfiles is that I can’t get it to install packages from repo … Is it something that I do wrong or docker is just that buggy? My third try it will maybe be to export ubuntu with the installed packages to a tar archive and then create a docker file that will use the archive.
Probably the problem you are facing is because of the CMD you are using. Is apache that you used in the CMD a script or are you calling the apache binary. If its the latter you should consider using apachectl to start the apache process in the container and you should keep it running in the foreground. So you will have to set CMD as shown below.
CMD ["apachectl", "-DFOREGROUND"]
Please let me know if that works.
Also please share the Dockerfile so that we will be able to help you to identify the reason why the package installation is not working for you.
You should keep apache running in foreground. If you just execute apachectl it will exit with an exit status 1 and as a result the container will stop.
root@37ddbb5caa7b:/# apachectl
Usage: /usr/sbin/apachectl start|stop|restart|graceful|graceful-stop|configtest|status|fullstatus|help
/usr/sbin/apachectl <apache2 args>
/usr/sbin/apachectl -h (for help on <apache2 args>)
root@37ddbb5caa7b:/# echo $?
1
root@37ddbb5caa7b:/#
See the above snippet , this is whats happening with your container. Its doing what its asked to do.
To keep the container running the process thats started with the container should stay without exiting. Thats why I have asked you to use the CMD as shown in my previous answer.
The container starts and it executes the script which you have in specified in the .sh file
The .sh file executes something ( starts the apache service ) and it exits with an exit status.
Container wont care about if the script which it executed started something in the background. For container to stay alive, the script should stay alive in the foreground.
So in our case, apachectl -DFOREGROUND stays in the foreground without existing. Which keeps the container alive. And if due to some reason apachectl dies, the container will also exit.
The above reasons will help you understand why your script didnt work