Tips & Tricks

Clean every unused images, containers, networks & build cache)

docker system prune -a

Delete all containers at once

docker rm -f $(docker ps -aq)

Build image in docker compose

It is possible to build an image directly inside docker compose.

udf:
    build: https://github.com/Crackvignoule/tradingview-udf-binance-node.git
    restart: always
    ports:
      - "9090:443"

Even better, you can specify a branch, example for dev branch:

build: https://github.com/Crackvignoule/tradingview-udf-binance-node.git#dev

Get container start command

You started a container with docker run CLI but you forgot the command you used ? You can kinda get it back with these steps:

  1. Get your container ID (you can just take a few char if you want):

docker ps
  1. Run this with your ID at the end (lets say b0ca0c234177):

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike b0ca0c234177

If you think you'll use it frequently you can add an alias to your ~/.bashrc or ~/.zshrc:

alias runlike="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike"

After restarting your terminal, you can use it like this:

runlike rclone  # container name
runlike c64  # container ID

Run GUI apps in docker in WSL2 using WSLg

docker run -it --rm \
  -v $(pwd):/app \
  -e DISPLAY=:0 \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  -e XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir \
  -e PULSE_SERVER=/mnt/wslg/PulseServer \
  image

If fonts are missing in your app, it may be necessary to install fonts, on alpine I needed to run this for firefox to work properly:

apk add font-noto font-noto-cjk font-noto-emoji

Last updated