DEV Community

Dylan Ballandras
Dylan Ballandras

Posted on • Originally published at dylan-ballandras.fr on

1

Use Docker to quickly start 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.

Installing and running Node/NPM based projects

Imagine running a Snowpack or Gatsby 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

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

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

Enter fullscreen mode Exit fullscreen mode

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/.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:

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay