基础环境
环境:ubuntu20.04 x64
使用apt install docker.io安装docker
docker版本:
root@ky:/userdata/testOnebuttonDeploy/shsany_ai/kyai_arm_ubuntu# docker -v
Docker version 24.0.5, build 24.0.5-0ubuntu1~20.04.1
docker run --help
root@nvidia:~# docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Create and run a new container from an image
Aliases:
docker container run, docker run
Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
--annotation map Add an annotation to the container (passed through to the OCI runtime) (default map[])
-a, --attach list Attach to STDIN, STDOUT or STDERR
--blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
--blkio-weight-device list Block IO weight (relative device weight) (default [])
--cap-add list Add Linux capabilities
--cap-drop list Drop Linux capabilities
--cgroup-parent string Optional parent cgroup for the container
--cgroupns string Cgroup namespace to use (host|private)
'host': Run the container in the Docker host's cgroup namespace
'private': Run the container in its own private cgroup namespace
'': Use the cgroup namespace as configured by the
default-cgroupns-mode option on the daemon (default)
--cidfile string Write the container ID to the file
--cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
--cpu-rt-period int Limit CPU real-time period in microseconds
--cpu-rt-runtime int Limit CPU real-time runtime in microseconds
-c, --cpu-shares int CPU shares (relative weight)
--cpus decimal Number of CPUs
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
-d, --detach Run container in background and print container ID
--detach-keys string Override the key sequence for detaching a container
--device list Add a host device to the container
--device-cgroup-rule list Add a rule to the cgroup allowed devices list
--device-read-bps list Limit read rate (bytes per second) from a device (default [])
--device-read-iops list Limit read rate (IO per second) from a device (default [])
--device-write-bps list Limit write rate (bytes per second) to a device (default [])
--device-write-iops list Limit write rate (IO per second) to a device (default [])
--disable-content-trust Skip image verification (default true)
--dns list Set custom DNS servers
--dns-option list Set DNS options
--dns-search list Set custom DNS search domains
--domainname string Container NIS domain name
--entrypoint string Overwrite the default ENTRYPOINT of the image
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
--expose list Expose a port or a range of ports
--gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs)
--group-add list Add additional groups to join
--health-cmd string Command to run to check health
--health-interval duration Time between running the check (ms|s|m|h) (default 0s)
--health-retries int Consecutive failures needed to report unhealthy
--health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s)
--health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s)
--help Print usage
-h, --hostname string Container host name
--init Run an init inside the container that forwards signals and reaps processes
-i, --interactive Keep STDIN open even if not attached
--ip string IPv4 address (e.g., 172.30.100.104)
--ip6 string IPv6 address (e.g., 2001:db8::33)
--ipc string IPC mode to use
--isolation string Container isolation technology
--kernel-memory bytes Kernel memory limit
-l, --label list Set meta data on a container
--label-file list Read in a line delimited file of labels
--link list Add link to another container
--link-local-ip list Container IPv4/IPv6 link-local addresses
--log-driver string Logging driver for the container
--log-opt list Log driver options
--mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33)
-m, --memory bytes Memory limit
--memory-reservation bytes Memory soft limit
--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
--memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
--mount mount Attach a filesystem mount to the container
--name string Assign a name to the container
--network network Connect a container to a network
--network-alias list Add network-scoped alias for the container
--no-healthcheck Disable any container-specified HEALTHCHECK
--oom-kill-disable Disable OOM Killer
--oom-score-adj int Tune host's OOM preferences (-1000 to 1000)
--pid string PID namespace to use
--pids-limit int Tune container pids limit (set -1 for unlimited)
--platform string Set platform if server is multi-platform capable
--privileged Give extended privileges to this container
-p, --publish list Publish a container's port(s) to the host
-P, --publish-all Publish all exposed ports to random ports
--pull string Pull image before running ("always", "missing", "never") (default "missing")
-q, --quiet Suppress the pull output
--read-only Mount the container's root filesystem as read only
--restart string Restart policy to apply when a container exits (default "no")
--rm Automatically remove the container when it exits
--runtime string Runtime to use for this container
--security-opt list Security Options
--shm-size bytes Size of /dev/shm
--sig-proxy Proxy received signals to the process (default true)
--stop-signal string Signal to stop the container
--stop-timeout int Timeout (in seconds) to stop a container
--storage-opt list Storage driver options for the container
--sysctl map Sysctl options (default map[])
--tmpfs list Mount a tmpfs directory
-t, --tty Allocate a pseudo-TTY
--ulimit ulimit Ulimit options (default [])
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
--userns string User namespace to use
--uts string UTS namespace to use
-v, --volume list Bind mount a volume
--volume-driver string Optional volume driver for the container
--volumes-from list Mount volumes from the specified container(s)
-w, --workdir string Working directory inside the container
root@nvidia:~#
docker run --help中文翻译
root@nvidia:~# docker run --help
用法:docker run [选项] 图像 [命令] [参数...]
从镜像创建并运行一个新的容器
别名:
docker container run, docker run
选项:
--add-host list 添加自定义主机到IP映射 (主机:ip)
--annotation map 给容器添加注释(传递给OCI运行时)(默认map[])
-a, --attach list 连接到STDIN,STDOUT或STDERR
--blkio-weight uint16 块IO(相对权重),在10和1000之间,或0禁用(默认0)
--blkio-weight-device list 块IO权重(相对设备权重)(默认[])
--cap-add list 添加Linux权限
--cap-drop list 删除Linux权限
--cgroup-parent string 容器的可选父cgroup
--cgroupns string 使用的cgroup命名空间(host|private)
'host': 在Docker host的cgroup命名空间中运行容器
'private': 在其私有的cgroup命名空间中运行容器
'': 使用由
默认的cgroupns-mode选项在daemon上配置的cgroup命名空间(默认)
--cidfile string 将容器ID写入文件
--cpu-period int 限制CPU CFS (完全公平调度)周期
--cpu-quota int 限制CPU CFS (完全公平调度)配额
--cpu-rt-period int 以微秒限制CPU实时周期
--cpu-rt-runtime int 以微秒限制CPU实时运行时间
-c, --cpu-shares int CPU份额(相对权重)
--cpus decimal CPU数量
--cpuset-cpus string 允许执行的CPU(0-3,0,1)
--cpuset-mems string 允许执行的内存(0-3,0,1)
-d, --detach 在后台运行容器并打印容器ID
--detach-keys string 重写用于分离容器的键序列
--device list 向容器添加主机设备
--device-cgroup-rule list 向cgroup允许的设备列表添加规则
--device-read-bps list 限制从设备读取速率(字节/秒)(默认 [])
--device-read-iops list 限制从设备读取速率(IO/秒)(默认 [])
--device-write-bps list 限制向设备写入速率(字节/秒)(默认 [])
--device-write-iops list 限制向设备写入速率(IO/秒)(默认 [])
--disable-content-trust 跳过图像验证 (默认 true)
--dns list 设置自定义DNS服务器
--dns-option list 设置DNS选项
--dns-search list 设置自定义DNS搜索域
--domainname string 容器NIS域名
--entrypoint string 覆盖镜像的默认ENTRYPOINT
-e, --env list 设置环境变量
--env-file list 读取一个环境变量文件
--expose list 开放一个端口或一系列端口
--gpus gpu-request 添加到容器的GPU设备 ('all'表示传递所有GPU)
--group-add list 添加额外的组以加入
--health-cmd string 运行检查健康状态的命令
--health-interval duration 运行检查之间的时间(ms|s|m|h)(默认0s)
--health-retries int 报告不健康需要连续失败的次数
--health-start-period duration 容器开始初始化之前的启动期(ms|s|m|h)(默认0s)
--health-timeout duration 允许运行一个检查的最大时间(ms|s|m|h)(默认0s)
--help 打印用法
-h, --hostname string 容器主机名
--init 在容器内部运行一个转发信号和清理进程的init
流程:
-i, --interactive 即使未连接,也保持STDIN打开
--ip string IPv4地址(例如,172.30.100.104)
--ip6 string IPv6地址(例如,2001:db8::33)
--ipc string 使用的IPC模式 // arnold:允许容器中的进程可以与主机上的其他进程进行通信,或者与其他也使用了 --ipc=host 的容器进行通信
--isolation string 容器隔离技术
--kernel-memory bytes 内核内存限制
-l, --label list 在容器上设置元数据
--label-file list 读取标签的行分隔文件
--link list 添加链接到另一个容器
--link-local-ip list 容器IPv4/IPv6链路本地地址
--log-driver string 容器的日志驱动程序
--log-opt list 日志驱动程序选项
--mac-address string 容器MAC地址(例如,92:d0:c6:0a:29:33)
-m, --memory bytes 内存限制
--memory-reservation bytes 内存软限制
--memory-swap bytes 交换限制等于内存加交换:'-1'表示启用无限交换
--memory-swappiness int 调整容器内存交换性(0至100)(默认-1)
--mount mount 将文件系统挂载附加到容器
--name string 为容器指定一个名称
--network network 将容器连接到网络
--network-alias list 为容器添加网络范围别名
--no-healthcheck 禁用任何容器指定的HEALTHCHECK
--oom-kill-disable 禁用OOM Killer
--oom-score-adj int 调整主机的OOM偏好(-1000至1000)
--pid string 使用的PID命名空间
--pids-limit int 调整容器pid限制(设置为-1表示无限)
--platform string 如果服务器具有多平台能力,则设置平台
--privileged 给予此容器扩展权限
-p, --publish list 将容器的端口发布到主机
-P, --publish-all 将所有公开的端口发布到随机端口
--pull string 运行前拉取图像("always", "missing", "never")(默认"missing")
-q, --quiet 抑制拉取输出
--read-only 将容器的根文件系统挂载为只读
--restart string 容器退出时应用的重启策略(默认"no")
--rm 容器退出时自动删除
--runtime string 此容器使用的运行时
--security-opt list 安全选项
--shm-size bytes /dev/shm的大小
--sig-proxy 将接收到的信号代理到进程(默认true)
--stop-signal string 停止容器的信号
--stop-timeout int 停止容器的超时时间(以秒为单位)
--storage-opt list 容器的存储驱动程序选项
--sysctl map Sysctl选项(默认map[])
--tmpfs list 挂载一个tmpfs目录
-t, --tty 分配一个伪TTY
--ulimit ulimit Ulimit选项(默认[])
-u, --user string 用户名或UID(格式:<name|uid>[:<group|gid>])
--userns string 使用的用户命名空间
--uts string 使用的UTS命名空间
-v, --volume list 绑定挂载一个卷
--volume-driver string 容器的可选卷驱动程序
--volumes-from list 从指定的容器挂载卷
-w, --workdir string 容器内的工作目录
root@nvidia:~#
示例记录
创建容器环境变量
比如我想将容器名称以环境变量的形式传递给容器,如下所示:
docker run -e CONTAINER_NAME=my_container_name ...
这样,在容器内部就可以使用 $CONTAINER_NAME
来获取到容器名称了。
ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ
ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ ᅟᅠ