The command docker run
process a container to be run in isolated form. When docker runs it has its own file system, networking, and its own isolated process tree separated from the host machine.
docker run
Syntax (General)$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
Here, IMAGE
must be specified to derive the container.
And Options : --add-host
, --attach
or -a
, --expose
, —hostname
or -h
, --network
, —name
, --rm
, --env-file
, —tty
or -t
, etc.
Note: Since the run
command interacts with containers, the new command docker container run
is preferred to use.
Preferred one:
$ docker container run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]
$ docker container run sbmagar/demoapp --name demoapp
Here, --name <container_name>
is used to define the container name for the image.
You can define different options when executing docker run
or docker container run
like the following:
$ docker container run -d sbmagar/demoapp
It runs the container in the background. You can use -d=true
or just -d
.
-d
)$ docker container run sbmagar/demoapp
--name <container_name>
)$ docker container run -d sbmagar/demoapp --name demoapp
-i
and -t
)$ docker container run -d -i -t sbmagar/demoapp /bin/sh --name demoapp
Here, -i
and -t
must use together to be run in interactive mode(terminal and pseudo-tty). You can use it as -ti
or -it
as well.
The output will be similar:
Output
root@232131234:/#
$ docker container run -d -p 80:8000 sbmagar/demoapp --name demoapp
Here, port 8000
is the port used by the container, and 80
is the port to be used by the host machine.