Home>Article>Operation and Maintenance> What is run in docker

What is run in docker

WBOY
WBOY Original
2022-07-08 10:25:58 12471browse

In docker, run is a command used to create a new container and run a command; when executing "docker run", Docker will start a process and allocate its exclusive files to the process. System, exclusive network resources and process group with this process as the root process, the syntax is "docker run [OPTIONS] IMAGE [COMMAND] [ARG...]".

What is run in docker

The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.

What is run in docker

docker run: Create a new container and run a command

Docker will encapsulate related processes into mutually isolated containers when executed ( container). When docker run is executed, Docker will start a process and allocate to this process its exclusive file system, exclusive network resources, and process group with this process as the root process. The Image loaded when Docker starts the container may have a default startup process defined, which requires the exposer's network port and other resources defined in the Dockerfile. But you can redefine this image by default using docker run. This is why the run command has more parameters than other docker command parameters.

Syntax

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 used together with -t;

  • -P: Random port mapping, the container’s internal port is randomly mapped to the host’s port

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

  • -t: Reassign a pseudo input terminal to the container, usually used together with -i;

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

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

  • --dns-search example.com: Specifies the container DNS search domain name, the default is consistent with the host;

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

  • -e username="ritchie": Set the environment variable;

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

  • --cpuset="0-2" or --cpuset="0,1,2": Bind The container runs on the specified CPU;

  • -m: Sets the maximum memory used by the container;

  • --net="bridge": Specifies the container Network connection type, supports 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

The example is as follows:

Use the docker image nginx:latest to start a container in background mode and name the container mynginx.

docker run --name mynginx -d nginx:latest

Use the image nginx:latest to start a container in background mode and map the container's port 80 to a random port on the host.

docker run -P -d nginx:latest

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

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

Bind the 8080 port of the container and map it to port 80 of the local host 127.0.0.1.

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

Recommended learning: "

docker video tutorial"

The above is the detailed content of What is run in docker. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn