Docker cheatsheet
Use this cheatsheet while going through the repo examples
Last updated
Use this cheatsheet while going through the repo examples
Last updated
Docker command-line reference
or
Options
-it
- these are two short options joined together:
-i
for "interactive" (read from STDIN, keep open even when not attached)
-t
for TTY (attaches a pseudo-TTY, which makes interaction inside container behave like a normal terminal session)
--rm
- automatically remove the container when it exits (generally when the process running as PID 1 terminates), so that the stopped container no longer consumes resources on the host system
--name NAME
- generally a good idea to name the container since it makes it easier to reference it from other commands
--entrypoint
- use this if you want to run a custom command and specifying CMD shown the first way doesn't work
Press the following key sequence to detach: CTRL-P,CTRL-Q
You will then be detached from the container (you may see read escape sequence
printed) and returned to the prompt.
To reattach to the container, enter: docker attach CONTAINER
-f
option is used to continuously "follow" log output (like the Unix tail
command).
Run docker help logs
to see other useful options.
The image for a container might specify an entrypoint. This changes the behavior of the docker run
command slightly and is generally done for running containers that should behave as dedicated tools. Anything specified after IMAGE is not used to run a command in the container, but is instead passed as options to the defined entrypoint command.
Sometimes, however, you want to be able to override the default entrypoint and specify the command to run the way you can with containers that don't have defined entrypoints. You can do this with the --entrypoint
option.
Many users find it convenient to override the default key sequence. One reason is that the default sequence interferes with using CTRL-P
to scroll through previous commands if you're using a shell in an attached terminal. See for details.