Docker run: Create a new container and run a command
Grammar:
Docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Options Description:
-A stdin: Specifies the standard input and output content type, 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 in conjunction with-t;
- P: port mapping in the format: host (host) port: Container Port
- T: reallocate a pseudo-input terminal to the container, usually with-I;
--name= "nginx-lb": Specify a name for the container;
--dns 8.8.8.8: Specifies the DNS server used by the container, default and host consistent;
--dns-search example.com: Specifies the container DNS search domain name, default and host consistent;
- H "Mars": Specifies the hostname of the container;
- e Username= "Ritchie": setting environment variables;
--env-file=[]: reads from the specified file into the environment variable;
--cpuset= "0-2" or--cpuset= "0,1,2": binds the container to the specified CPU to run;
- m: sets the maximum amount of memory used by the container;
--net= "Bridge": Specifies the network connection type of the container, supports the bridge/host/none/container:<name|id> four types;
--link=[]: add link to another container;
--expose=[]: open a port or a set of ports;
Instance
Use Docker image nginx:latest to start a container in background mode and name the container Mynginx:
Docker Run--name mynginx-d nginx:latest
Use mirror nginx:latest to start a container in background mode and map the container's 80 port to the host random port:
Docker Run-p-D nginx:latest
Using mirrored nginx:latest, start a container in background mode, map the container's 80 port to the host's 80 port, and the host's directory/data map to the/data of the container:
Docker run-p 80:80-v/data:/data-d nginx:latest
Bind the container's 8080 port and map it to port 80 on the local host 127.0.0.1:
Docker run-p 127.0.0.1:80:8080/tcp Ubuntu bash
Use mirror nginx:latest to start a container in interactive mode and execute the/bin/bash command inside the container:
Docker run-it Nginx:latest/bin/bash
"Docker Command"-run command