What compose command do?
The "docker-compose up --build" command is used to build and start a Docker container with the services defined in a Docker Compose file.
The "--build" flag tells Docker Compose to build any images that are not yet built or have changed since the last build. This means that Docker Compose will look for a Dockerfile in the directory specified for each service in the Compose file, and use it to build a Docker image.
The command "docker-compose up" starts the container, and the "--build" flag specifies that the image should be rebuilt before starting the container.
Overall, the command "docker-compose up --build" is useful when you have made changes to your Dockerfile or any of the files that your Docker image depends on, and you want to ensure that those changes are reflected in the running container.
How to use $docker-compose up --build in Laravel
The first step to getting your project dockerized is that you have to install laravel sail.
Sail -> Intro
Sail is a CLI tool for Laravel that simplifies the development, testing, and deployment of Laravel applications using Docker containers. It provides a lightweight and easy-to-use interface for managing Docker containers and streamlines the setup process for new projects. Sail allows developers to focus on building their applications rather than configuring complex Docker environments.
Commands to get a sail-Laravel
You have to open your project which you want to dockerize then open the terminal and type the commands below:
#1.
composer require laravel/sail --dev
#2.
php artisan sail:install
#3.then it will ask what you want to install
The "sail: install" command in Laravel generates a Docker Compose file for your application, which includes all of the services that your application needs to run in a Docker container. This Compose file specifies the images, ports, environment variables, volumes, and other configuration options required to run your application in a Docker environment. By generating this file, Sail simplifies the process of setting up a Docker environment for your Laravel application and allows you to focus on building your application rather than managing the Docker infrastructure.
Now I'LL run docker-compose up --build
After running the "docker-compose up --build" command in the terminal, you should see an output that shows the progress of the build process, including the download and installation of any necessary Docker images and the building of your application's Docker image.
Now time to check if the container is there or not
To check if your Docker container is running, you can use the "docker ps" command in the terminal. This will show a list of all running Docker containers, including their ID, status, and other information. If your container is running, it should appear in the list. If you want to see a list of all containers, including those that are not currently running, you can use the "docker ps -a" command. This will show a list of all containers along with their status, ID, and other information.
Everything is working Allhumdullah*! See you in the next blog*
Take-care*!*