Docker beginner gotchas

I started using Docker recently and there was one thing I didn’t understand – initially.

So, when running your Dockerfile if you don’t have a CMD command the container will continue to run. However, when you include CMD command the container will exit unless you run one of your programs in the foreground. So, you’ll have to do something like this:

CMD bash -c "apachectl -D FOREGROUND"

if you are running Apache, of course, that will be different if you are running different software.

Another thing is that the CMD is where you want to run you dependencies installation, like PHP’s composer intall and NOT in the RUN commands. Here is how my CMD looked like in the end:

CMD bash -c "composer install && chmod -R 777 /path/to/project/storage/ /path/to/project/bootstrap/ && php /path/to/project/artisan migrate --force && apachectl -D FOREGROUND"

Note that I am a complete noob when it comes to Docker so take this with a grain of salt. This is only my noob understanding.