Docker run the basic usage

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/fu_huo_1993/article/details/102530025

docker run Command to create and start a container

语法:docker run [options] image [command] [args…]

示例: Docker run -dit -v alias: the volume inside the container path [-P] [-p Port: port] --memory = 200M --cpu-shares = 10 --name to the container from the name --net mynet --ip 172.18.0.2 --volumes-from the container name mirror name

命令解释docker run the command interpreter

	• -d	后台运行
	-i	交互式运行
	-t	tty终端
	--memory	限制容器可以使用的内存,如果没有指定 --memory-swap 那么默认和--memory一样大
		eg:  --memory 200m 没有--memory-swap参数,那么容器可以使用的内存为400m
	--memory-swap	设置swap区可以使用的内存大小,默认和--memory一样大,必须>=--memory
	--cpu-shares	表示占有cpu的相对权重
		eg:    
		     假设在同一台物理主机上启动了如下2个容器,容器1占用的cpu是容器2占有的cpu的2倍。
		同一台物理主机上
		
		容器1:
		docker run -d  --cpu-shares 10  容器名 
		容器2:
		docker run  -d  --cpu-shares 5  容器名 
	--name	给容器起的名字
	--net	指定容器运行的网络(也可以是自己创建的网络 docker network create --subnet=172.18.0.0/24  mynet)
	-v	指定volume的路径
		data volume模式:
		 别名:容器里面的路径
		mysql:/var/lib/mysql
		/var/lib/mysql 为Dockerfile 中的volume的值
		使用  docker volume ls 命令查看
		本地创建 mysql 数据卷:docker create volume --name mysql
		bind mouting模式:
		本地路径:容器路径 
		/var/data:/var/容器目录
		本地目录和容器目录中的文件修改都会实时同步。
	--ip	指定容器的ip地址
	-P	随机映射一个端口
	-p	本地端口:容器端口。    将容器中的某个端口映射到本地的某个端口上
	-e	设置环境变量
	--volumes-from	参数用于连接某个指定容器的卷,从而可以访问到指定容器中的所有的卷。示例:blog_demo表示新容器中挂载了blog_demo容器中所有的卷。
	--rm	表示容器运行完成后自动删除
	-h	设置host主机的名称

Guess you like

Origin blog.csdn.net/fu_huo_1993/article/details/102530025