Setting Up Laravel 100% with Docker on a New Device

Dockerizing Your Development Environment from Scratch


I frequently speak with individuals on how to setup work environments. There’s still a large community that rejects Docker; I’m assuming because they don’t know how to use it fully. In this article, I want to show how to use Docker to setup an environment on your computer. That’s all you need. You won’t need anything else and it doesn’t matter which operating system you’re using. Never will you have to worry about changing versions on your computer. You can do it all through Docker.

New Projects

If we visit the Laravel documentation, it goes through the setup process for each environment. For example, for macOS and Linux, it states to use this command:

curl -s | bash

Since curl and bash are both installed out of the box with macOS environments, we don’t have to worry about that. Just run the command.

Once installed, it’ll specify to run ./vendor/bin/sail up to start the container. That container will start. You’ll be able to access your Docker environment, click on the Laravel container and access the terminal inside of the container. From there you can run all of your commands that involve composer or npm since they’re already pre-loaded with your Docker environment.

Open your Docker Desktop to see your project running.


Click on laravel.test-1 to open the container and then click on the terminal tab. From now on, this is where we’ll enter all of our commands from.



That’s it for new projects. As easy as it gets.

Existing Projects

There are a couple of things that are different that we need to do. Believe it or not, git is something that’s installed by default on most Mac and Linux machines. However, if it’s not, we can grab the git image.

Open your terminal and run the following command:

docker pull alpine/git

This will allow us to use git from now on. As soon as it’s pulled, you can start executing the commands, such as cloning a project.

docker run -ti --rm -v ${HOME}:/root -v $(pwd):/www alpine/git clone

I have a www folder in my main directory, which is why I listed $(pwd):/www.

Once the project is cloned, we need to run composer install, but we don’t have composer on our machine. Let’s grab composer.

docker pull composer

We can now run composer commands, such as the install command.

docker run --rm --interactive --tty \
  --volume $PWD:/www/youtube-laravel \
  composer install

We want to run the composer install command in the directory that contains our project. This will install all of our vendor files. As soon as that’s complete, we can now run ./vendor/bin/sail up to start our project. We can then run all of our other commands from inside of the Docker container terminal, such as:

cp .env.example .env

php artisan key:generate

php artisan migrate --seed

npm install

npm run dev

I hope that you see how simple Docker is to use. You don’t need to know much about it, you just need to use to docs. For example, read the docs and you’ll see that the commands listed here are directly pulled from those images.—–158ae2e2727——————————–—–158ae2e2727——————————–


Leave a Reply