端口映射
docker run -p 容器外端口:容器内端口
[root@ip-10-0-3-12 ec2-user]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
58440236/nginx v1.12.2 4037a5562b03 3 years ago 108MB
[root@ip-10-0-3-12 ec2-user]# docker run --rm --name mynginx -d -p81:80 58440236/nginx:v1.12.2
8075e0efdb70ef0d80d5fb44238fae9220ea6c02911ea9a12dfaf7ca2ecd6e90
[root@ip-10-0-3-12 ec2-user]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8075e0efdb70 58440236/nginx:v1.12.2 "nginx -g 'daemon of…" 4 seconds ago Up 4 seconds 0.0.0.0:81->80/tcp mynginx
[root@ip-10-0-3-12 ec2-user]# netstat -luntp|grep 81
tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 1587/docker-proxy
[root@ip-10-0-3-12 ec2-user]# curl 127.0.0.1:81
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
挂载数据卷
docker run -v 容器外目录:容器内目录
传递环境变量
docker run -e 环境变量key=环境变量value
容器内安装软件(工具)
yum/apt-get/apt等