Shortcut for “docker run”
Docker is one of my daily drivers in my local development toolchain. I mostly rely on it for spawning dedicated development environments, which are tailored to the specific project I’m working on.
I usually add a Dockerfile
or docker-compose.yml
file rather early to my projects. (Independent of whether I actually use Docker in production.) However, for initial prototyping, or for just briefly trying something in an ad-hoc manner, I created a small shortcut that I find quite handy.
It’s called dckr
(for brevity) and it starts a disposable Docker container with the current host working directory mounted into it. So you basically take over the current folder into a container to carry on working on it.
To use the dckr
shortcut, you append the image name and (optionally) additional arguments like so:
dckr node:22
for jumping into a NodeJS REPLdckr -p 8080:8080 python:3.12 /bin/bash
for launching a shell with a Python runtime and exposing port8080
on the host
You can define the dckr
utility as shell alias (1) or as dedicated shell script (2).
(1) Shell alias
alias dckr='docker run -it --rm --workdir /app --volume `pwd`:/app'
This definition could live in your .bashrc
file.
(2) Shell script
#!/bin/bash
docker run \
-it \
--rm \
--workdir /app \
--volume "$(pwd):/app" \
"$@"
This script would have to reside in your $PATH
. The script file needs to be executable.