Notes/Docker

Handy Docker Commands

I love Docker. Being able to spin up a project with infrastructure of varying degrees of complexity without messing up your local environment in the process is awesome. That said the more useful commands can become a challenge to recall, so I've compiled this list of handy docker commands.

As time goes on I'll add to the list. If you find the list helpful and would like to make an addition, just reach out to me via the contacts on the site.

But save yourself some keystrokes and add the following to your profile script.

# PowerShell

# "docker" shortcut
function d {
    docker run --rm -itv ${pwd}:/app $args
}

# "docker-compose" shortcut
function dc {
    docker-compose $args
}

Composer

# Everything automatically is run as a composer command
d composer $cmd
# EG Run composer install
d composer install

# Expedite installs and updates by using composer with the prestissimo plugin
# Fingers crossed that the improvements it brings will make it into v2
d gsingh1/prestissimo install

PHP

CLI

d php:alpine $cmd
# EG Run PHPUnit
d php:alpine sh -c "cd app ; php vendor/bin/phpunit"

NodeJS

# EG Run npm install
d node:alpine sh -c "cd /app ; npm install"

Utilities

Instant Mailbox

Handy for catching emails generated by applications. With the below snippet, you'll have a GUI at http://localhost:1080/ and can send mail to port 1025.

docker run -p 1080:80 -p 1025:25 djfarrelly/maildev