Home

moon indicating dark mode
sun indicating light mode

Fast start-up projects with Docker

August 19, 2020

I just installed WSL2 on my computer with an pristine Ubuntu 20.04 installation and 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

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:


kayneth_db
Dylan Ballandras aka Kayneth
(as from the Lord in Fate Zero 😉)