Run a container

A container is a capsule. Every command below was run on Linux, rootless, and its output is pasted as printed.

Run with limits and a volume

$ corail run --rm --memory 64m --cpus 1 --pids-limit 64 -v /srv/data:/data:ro alpine -- cat /data/greeting.txt
hello

--rm deletes the container when it exits. -v host:ctr[:ro] bind mounts a directory. --memory takes a byte count or a k, m or g suffix. The target is an image (pulled if it is not cached) or a path to a rootfs directory. A command after -- replaces the image's default Cmd. The full flag list is on Commands.

The exit status of the container is the exit status of corail run:

$ corail run --rm alpine -- sh -c 'exit 3'; echo $?
3

Run in the background, then manage it

$ corail run -d --name web --memory 64m alpine -- sh -c 'echo started; sleep 300'
web
$ corail ps
ID                       PID      STATUS   COMMAND
web                      47722    running  sh
$ corail logs web
started
$ corail exec web -- uname -a
Linux web 6.17.0-35-generic #35~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 19:30:42 UTC 2 x86_64 Linux
$ corail stop web
web
$ corail ps
ID                       PID      STATUS   COMMAND
web                      47722    exited   sh
$ corail rm web
web

stop sends the stop signal and waits up to --grace seconds before killing. A stopped container stays in ps as exited until rm.

Images

$ corail pull alpine
corail: pulled library/alpine:latest
$ corail images
REPOSITORY                       TAG              LAYERS
library/alpine                   latest           1
$ corail prune
corail: pruned 2 blob(s), reclaimed 3.7 MiB
$ corail rmi alpine
library/alpine:latest

prune deletes cached download blobs and keeps extracted layers, so images keep running from cache. rmi removes the image record.

Rootless limits

Without root, --net supports host (the default) and none. bridge and -p need root.

Next: run a group of containers.