Running a container in Docker

To run a container you can simply type:

$docker run <image name>

Some of the flags available are the following:

Flag

Effect

-i
Attaches the stdout and stdin to the container.
-t
Creates a fake tty for the container.
\-\-rm
Removes the image as soon as it is exited.
\-\-name <container name>
Gives the container a name to be used as a
reference when managing. If not provided,
Docker will give it a random unique name.
-d
Detaches the input and output of the container
so as not to exit the container on exit.
-p <external>:<internal>
Attaches the <external> port to the <internal>
port on the container itself.
-P
Attaches a random external port to the
internal port on the container itself.
-e <key>=<value>
Changes the <key> environment variable to the
<value> value inside the container.
\-\-mount \-\-type=bound,source=
<path to source>,target=
<path to target>
Mounts the local filesytem <source> directory
to the container’s <target> directory. It is
required that no space is given after commas.
\-\-restart <restart type>


The restart policy can take on 4 values, being
“no”, “on-failure”, “unless-stopped”, “always”.
To restart after reboot, use “unless-stopped”.

For more advanced commands refer to the official Docker documentation.