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/kipavy/tradingview-udf-binance-node.git
    restart: always
    ports:
      - "9090:443"

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

circle-exclamation
build: https://github.com/kipavy/tradingview-udf-binance-node.git#dev

You can also specify a custom Dockerfile name using context:

services:
  web:
    build:
      # build context: where to look for Dockerfile, as seen it can also be a distant URL
      context: ./app
      # Custom Dockerfile name, relative to the context directory
      dockerfile: Dockerfile.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):

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

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

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

Run GUI apps in docker in WSL2 using WSLg

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:

Get container IP from service name

Get container IP from id or name

Get volume mount folder

Last updated