docker run : Create a new container and run a command OPTIONS description: -a stdin: Specifies the standard input and output content type, with three optional STDIN/STDOUT/STDERR items -d: Run the container in the background and return the container ID -i: Runs the container in interactive mode, usually in conjunction with-t -P: Random port mapping, container internal port 随机 Port mapped to the host -p: Specify port mapping. Format: host (host) port: container port -t: Reassign a pseudo-input terminal to the container, usually used with-I –name=”nginx-lb”: Specify a name for the container –dns 8.8.8.8: Specifies the DNS server used by the container, which is the same as the host by default –dns-search example.com: Specifies the container DNS search domain name, which is the same as the host by default -h “mars”: Specify the hostname of the container -e username=”ritchie”: Set environment variabl –env-file=[]: Read environment variables from the specified file –cpuset=”0-2” or –cpuset=”0,1,2”: Bind the container to the specified CPU run -m : Set the maximum memory used by the container –net=”bridge”: Specifies the network connection type of the container, which supports bridge/host/none/container: four types –link=[]: Add a link to another container –expose=[]: Open a port or group of ports –volume , -v: Bind a volume Use the docker mirror nginx:latest to start a container in background mode and name the container mynginx. Use mirrored nginx:latest to start a container in background mode and map the container’s port 80 to the host random port. Using mirror nginx:latest, start a container in background mode, mapping port 80 of the container to port 80 of the host, and the directory / data of the host to the / data of the container. Bind port 8080 of the container and map it to port 80 of the local host 127.0.0.1. Use the mirror nginx:latest to start a container in interactive mode and execute the / bin/bash command inside the container. 2.30.1. Grammar ¶
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
2.30.2. Example ¶
docker run --name mynginx -d nginx:latest
docker run -P -d nginx:latest
docker run -p 80:80 -v /data:/data -d nginx:latest
$ docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
runoob@runoob:~$ docker run -it nginx:latest /bin/bash
root@b8573233d675:/#