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.

Problems copying Laravel Sail project from fresh install into existing project

Today, I wanted to get a fresh Laravel 8 install on a project I started recently, basically restarting, as I needed the teams functionality of Jetstream and you can’t add the teams functionality into a project which already has Jetstream. So, I tried creating a fresh Laravel install and copying the files over to my project but for some reason the MySQL container didn’t get installed, which was confusing at first. Anyway, I ended up deleting the ‘vendor’ folder and installing everything a new with composer and then running:

php artisan sail:install

then I run

./vendor/bin/sail build --no-cache

and then just

./vendor/bin/sail up

this time MySQL worked and I could run my migrations.

I am sharing this in case someone else encounters a similar problem.