Basicly -a
is to attach a terminal device to the container.
Lets have some examples:
This will result in “test” beeing printed inside the container, but since stdout is not attached, you will not see anything in your terminal:
me@docker:~$ echo "test" | docker run --rm -i -a stdin alpine cat -
75f178eb4111829c78ada5b2ca0d5d7375ea19274caefb0cf7d73538bedfb8f4
me@docker:~$
This will result in “test” beeing printed inside the container to the attached stdout, and therefor be visible in your terminal
me@docker:~$ echo "test" | docker run --rm -i -a stdin -a stdout alpine cat -
test
me@docker:~$
… and even be passed to follow up pipes:
me@docker:~$ echo "test" | docker run --rm -i -a stdin -a stdout alpine cat - | grep test
test
me@docker:~$
This will result in an error of the ls command, because the test folder does not exist, but it will not be rendered, since errors are printed to stderr, which is not attached.
me@docker:~$ echo "test" | docker run --rm -i -a stdin -a stdout alpine ls $(cat -)
me@docker:~$
This will result in an error of the ls command, because the test folder does not exist, but this time stderr is attached and you will be able to see it in your terminal
me@docker:~$ echo "test" | docker run --rm -i -a stdin -a stdout -a stderr alpine ls $(cat -)
ls: test: No such file or directory
me@docker:~$
This finaly works, because the bin folder exists
me@docker:~$ echo "bin" | docker run --rm -i -a stdin -a stdout -a stderr alpine ls $(cat -)
arch
ash
base64
bbconfig
busybox
cat
chgrp
chmod
chown
conspy
cp
date
dd
df
dmesg
dnsdomainname
dumpkmap
echo
ed
egrep
false
fatattr
fdflush
fgrep
fsync
getopt
grep
gunzip
gzip
hostname
ionice
iostat
ipcalc
kbd_mode
kill
link
linux32
linux64
ln
login
ls
lzop
makemime
mkdir
mknod
mktemp
more
mount
mountpoint
mpstat
mv
netstat
nice
pidof
ping
ping6
pipe_progress
printenv
ps
pwd
reformime
rev
rm
rmdir
run-parts
sed
setpriv
setserial
sh
sleep
stat
stty
su
sync
tar
touch
true
umount
uname
usleep
watch
zcat
me@docker:~$
I hope this helps to clearify the usage.