每次启动时(在 MacOS 中)将本地目录挂载为 Docker 容器的卷的非常简单的单行终端命令是什么?
Not sure what you mean. You know that containers don't just start on their own (Unless you will use a serivce/script/cron/run etc).
You add volume by using -v/--volume option:
docker run -dit --name=FOO -v /Path/On/Host:/Path/In/Container Image
If you want to have it on boot you need probably a service (although I' don't know if they are available on mac)
[Unit]
Description=Foo Bar
After=docker.service
BindsTo=docker.service
Conflicts=shutdown.target reboot.target halt.target
[Service]
Environment=LOCAL_DIR='/Path/On/Host'
Environment=TARGET_DIR='/Path/On/Container'
Environment=IMAGE='YOUR_DOCKER_IMAGE'
TimeoutStartSec=0
TimeoutStopSec=30
Restart=always
RestartSec=10
ExecStartPre=-/usr/bin/docker rm -f Foo_Bar
ExecStart=/usr/bin/docker run -dit --name=Foo_Bar -v $LOCAL_DIR:$TARGET_DIR $IMAGE
ExecStop=/usr/bin/docker stop Foo_Bar
NotifyAccess=all
[Install]
WantedBy=multi-user.target
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.