English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Docker run command

Docker Command Summary

docker run :Create a new container and run a command

Syntax

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

OPTIONS description:

  • -a stdin: Specify the type of standard input/output content, optional STDIN/STDOUT/STDERR Three items;

  • -d: Run the container in the background and return the container ID;

  • -i: Run the container in interactive mode, usually with -t Simultaneously use;

  • -P: Random port mapping, container internal portRandomMap to the host's port

  • -p: Specify port mapping, format: Host (host) port: container port

  • -t: Reallocate a pseudo-TTY to the container, usually with -i Simultaneously use;

  • --name="nginx-lb": Specify a name for the container;

  • --dns 8.8.8.8: Specify the DNS server used by the container, default is the same as the host;

  • --dns-search example.com: Specify the DNS search domain for the container, default is the same as the host;

  • -h "mars": Specify the hostname of the container;

  • -e username="ritchie": Set environment variables;

  • --env-file=[]: Read environment variables from a specified file;

  • --cpuset="0-2 --cpuset="0,1,2: Bind the container to a specified CPU for execution;

  • -m :Set the maximum memory usage of the container;

  • --net="bridge": Specify the network connection type of the container, supporting bridge;/host/none/container: Four types;

  • --link=[]: Add a link to another container;

  • --expose=[]: Open a port or a group of ports;

  • --volume, -v: Bind a volume

Online Examples

Start a container in background mode using the docker image nginx:latest and name it mynginx.

docker run --name mynginx -d nginx:latest

Start a container in background mode using the image nginx:latest and map the container's80 port to a random port on the host.

docker run -P -d nginx:latest

Start a container in background mode using the image nginx:latest and map the container's 80 port mapped to the host's 80 port, the host directory /data mapped to the container's /data.

docker run -p 80:80 -v /data:/data -d nginx:latest

binding the container's 8080 port and map it to the local host 127.0.0.1 of 80 port.

$ docker run -p 127.0.0.1:80:8080/tcp ubuntu bash

Start a container in interactive mode using the image nginx:latest and execute/bin/bash commands.

w3codebox@w3codebox:~$ docker run -it nginx:latest /bin/bash
root@b8573233d675:/#

Docker Command Summary