Docker Run Command: Usage Guide & Examples

The “docker run” command is used to create and run a new container instance. Its basic usage is as follows:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

OPTIONS are optional parameters, IMAGE specifies the name of the image to be used, COMMAND indicates the command to be executed in the container, and ARG represents the command’s arguments.

For example, to run a container based on an nginx image, you can use the following command:

docker run -d -p 80:80 nginx

This command will run an nginx container in the background and map the container’s port 80 to the host’s port 80. You can also run the container in interactive mode by adding the -it parameter, as shown below:

docker run -it ubuntu /bin/bash

This command will start an Ubuntu container in interactive mode and open a /bin/bash shell. You can execute commands and interact with the container.

bannerAds