Docker is an open source application container engine, based on the Go language and open source in compliance with the Apache2.0 protocol.

Docker allows developers to package their applications and dependencies into a lightweight, portable container, and then publish it to any popular Linux machine, which can also be virtualized.

Docker run command syntax

Create a new container and run a command:

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

Docker run command example

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 put The container's port 80 is mapped 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 and change the container's 80 The port is mapped to port 80 of the host, and the host's directory /data is mapped to the container's /data.

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