docker run and docker exec differences
RUN Docker : The image to create a container and a run command, the operation target image ;
Exec Docker : Run run vessel, operating against a container .
docker run the command
grammar
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
OPTIONS Description:
-
stdin -a : Specifies the standard input and output content types, optionally STDIN / STDOUT / STDERR three;
-
-d : background container, and returns the container ID;
-
-i : Run vessel in interactive mode, typically used in conjunction with -t;
-
-P : random port mapping, inside the container ports randomly mapped to the host port of the high
-
-p : Specifies port mapping format: a host (host) port : a container port
-
-t : reassign a pseudo input terminal into a container, normally used in conjunction with -i;
-
= --name "Nginx-LB" : a name of the container;
-
8.8.8.8 - DNS : the DNS server to use the container specified, the default host and consistent;
-
example.com-Search - DNS : Specifies the DNS search domain container, and the default host agreement;
-
-H "Mars" : hostname specified container;
-
username = -e "Ritchie" : set environment variables;
-
File-= --env [] : read a file from the specified environment variable;
-
= --cpuset "0-2" or --cpuset = "0,1,2" : bind to a designated container CPU operation;
-
-m : setting the maximum memory using the container;
-
= - Net "Bridge" : network connection type of the container, support bridge / host / none / container:four types;
-
= --link [] : add a link to another vessel;
-
= --expose [] : opening a port or a group of ports;
-
--volume, -v : binding a roll
Examples
Use docker mirror nginx: mode starts after a latest table container, and the container was designated as my-nginx.
docker run --name my-nginx -p 8081:80 -d nginx:latest
Browser to http: // Host IP: 8081, the effect is as follows:
Mirroring Nginx: mode starts after a latest table container port 80 and container port random mapped to the host:
docker run -P -d nginx:latest
Mirroring nginx: after the latest start a container station mode, map the host port 80 to port 80, the container main directory / data mapped to the container / data:
docker run -p 80:80 -v /data:/data -d nginx:latest
Mirroring nginx: latest start a container in interactive mode, execute / bin / bash command in the container:
docker run -it nginx:latest /bin/bash
docker exec command
grammar
docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
OPTIONS Description:
-
-d : Split mode: running in the background
-
-i : Even without additional remains open STDIN
-
-t : assign a pseudo-terminal
In the container name my-nginx open a terminal interaction mode:
docker exec -it my-nginx /bin/bash
Or use containers ID 721eb23901ce terminal open an interactive mode:
docker exec -it 721eb23901ce /bin/bash