FahamLah

Commands

docker run

docker run [options] <image> [command]

Risk: Safe

What it does

Makes a new container from an image and starts it.

When to use it

Every time you want to run an app in a box.

Example

$ docker run -d --name web -p 8080:80 nginx:1.30-alpine

Run nginx in the background. Open hatch 8080.

$ docker run hello-world

Your first container: it prints a hello.

$ docker run --rm alpine:3.22 echo hi

Run once, then clean the box away.

$ docker run -it alpine:3.22 sh

Get a shell inside. Type exit to leave.

$ docker run -d -e POSTGRES_PASSWORD=secret postgres:18-alpine

Give the app a setting with -e.

$ docker run -d -v pgdata:/var/lib/postgresql postgres:18-alpine

Keep data in a locker (volume).