Docker Run
Basic usage
Check
hostnameCheck
PS1(bash prompt)Will pull automatically
Will close immediately after executing command
$ docker run bash
$ docker run bash echo 'hello'
hello
Interactive mode
-t,--tty- Allocate a pseudo-TTY-i,--interactive- Keep STDIN open even if not attached-it- implies both-iand-tctrl+p + ctrl+q- quit container without stopping itctrl + d- exits and stops the container
$ docker run -it bash
$ docker run -it alpine sh
Detach
-d,--detach- Run container in background and print container ID
$ docker run -d -it alpine sh
b7583714a497ac10fcfa2f514025dc271a9e0d4540684f26f115d5a98b2f87b7
$ docker run --detach -it alpine sh
09f99d54cba4162ebea238766d366fe09ad831ca9cc844c1b54f3151dd8aec3b
Attach
Attach to local standard input, output, and error streams of main process
ctrl + p + q- quit container without stopping it
$ docker attach CONTAINER_NAME_OR_ID
Show running
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09f99d54cba4 alpine "sh" About a minute ago Up About a minute serene_kare
b7583714a497 alpine "sh" About a minute ago Up About a minute cocky_curie
Show all containers
even not running
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09f99d54cba4 alpine "sh" About a minute ago Up About a minute serene_kare
b7583714a497 alpine "sh" About a minute ago Up About a minute cocky_curie
Name
--name- Assign a name to the container
$ docker run -d --name sleeper alpine sleep 50
b9e2e75cb7727cc43c6daff677b69d2fcae9077717c069190ab7bb3329339c4a
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b9e2e75cb772 alpine "sleep 50" 5 seconds ago Up 4 seconds sleeper
09f99d54cba4 alpine "sh" About a minute ago Up About a minute serene_kare
b7583714a497 alpine "sh" About a minute ago Up About a minute cocky_curie
Limiting resources
Assignments
Wyświetl
Ehlo World!z wnętrza konteneraalpineWyświetl listę działających i zakończonych kontenerów
Podaj rozmiar obrazu
nginxPodaj rozmiar kontenera stworzonego na podstawie obrazu
nginx