docker run -it --rm \ -p 8000:8000 \ solune/symfony:7.4-cli \ bash -c "yes n | symfony new --no-git . && yes n | symfony serve"
Application will be available at http://127.0.0.1:8000
If you want to understand the command above, continue reading.
As you may have noticed, the command is actually a few of well orchestred embedded commands.
docker run -it options provide us a better bash experience with an interactive shell.
docker run --rm option automatically removes the container when it exits.
Once the container is running, we can install and serve an application. We run actually a script inside the container, thanks to the pair
docker run and
bash -c option. The script we run inside the container is:
yes n | symfony new --no-git . yes n | symfony serve
The commands contain
yes no. This trick prevents us to be prompted for updating Symfony CLI.
symfony new command carries yet the
--not-git option. This command performs a couple of tasks, which includes the project git set up and an initial commit. It's great, but it doesn't work unless we set up our git identity. Remember we're inside a container. Adding this option we skip these actions.
symfony serve starts the web server at
localhost:8000 that serves our Symfony application. Remember, we are inside the container.
docker run -p 8000:8000 option. This makes the application available for us. This is mandatory because the container's ports aren't reachable from outside unless we ask for it. Note the
symfony serve command serves the application under the port
8000, but inside the container. Thanks to the docker port mapping, we can link a port into the container for us. In this case we use the same port number.
It's all about saving time. It's not about a smart shortcut. It's neither about a long script that performs boring tasks.