Use Docker to quickly start projects
Tags: docker, php, node
Published: 2020-08-25 08:06:10

---
title: Use Docker to quickly start projects
published: true
date: 2020-08-19 00:00:00 UTC
tags: docker, php, nodejs
canonical_url: https://www.dylan-ballandras.fr/blog/easily-start-up-projects/
---

I just installed WSL2 on my computer with an pristine Ubuntu 20.04 installationand I didn’t want to install most of languages and software I would use for my projects.

Then, I forced myself to use `docker run --rm` as much as possible.

Here are a few example for some type of projects.

## [<svg viewbox="0 0 16 16" width="16" height="16" fill="currentcolor" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#installing-and-running-nodenpm-based-projects)Installing and running Node/NPM based projects

Imagine running a [`Snowpack`](https://www.snowpack.dev/) or [`Gatsby`](https://www.gatsbyjs.com/) based project.

- `docker run --rm -it -v $PWD:/usr/src/app -w /usr/src/app node:12 yarn install`
- `docker run --rm -it -p 8000:8000 -v $PWD:/usr/src/app -w /usr/src/app node:12 yarn start`

## [<svg viewbox="0 0 16 16" width="16" height="16" fill="currentcolor" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#running-a-php-project)Running a PHP project

You could even `composer create`, `composer install` or `php -S 0.0.0.0:80 -t public` a Symfony project.

- `docker run --rm --interactive --tty --volume $PWD:/app composer create-project sylius/sylius-standard acme`
- `docker run --rm --interactive --tty --volume $PWD:/app composer install`
- `docker run -it --rm -p 8000:8000 -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.4-cli php -S 0.0.0.0:8000 -t public`

## [<svg viewbox="0 0 16 16" width="16" height="16" fill="currentcolor" aria-hidden="true"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg>](#keep-track-of-your-scripts)Keep track of your scripts

You can leverage a Makefile or Shell script to commit those scripts.

As an example, for my blog, I use the following configuration:

```

.DEFAULT\_GOAL := help

.SILENT: help

path := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE\_LIST)))))

app@install:

    docker run --rm -it -v ${path}:/usr/src/app -w /usr/src/app node:12 yarn install

app@run:

    docker run --rm -it -p 8000:8000 -v ${path}:/usr/src/app -w /usr/src/app node:12 yarn develop --host=0.0.0.0

```

* * *

Thank to that, I can try the next Node versions before pushing to production.

You can find how to easily do the same for any type of language by going to the [https://hub.docker.com/](https://hub.docker.com/).There is often a `Run a single script` part for the main Docker images.

Then, if you need to go further, using `docker-compose` seems to be interesting to create a “network” of container (eg. add a database, a mailcatcher, etc.).

Sources:

- [https://github.com/nodejs/docker-node](https://github.com/nodejs/docker-node)
- [https://hub.docker.com/\_/php](https://hub.docker.com/_/php)