Docker 按容器 A 的启动参数创建新容器 B

How to show the run command of a docker container - Stack Overflow

docker inspect --format "$(curl -s \
    https://gist.githubusercontent.com/efrecon/8ce9c75d518b6eb863f667442d7bc679/raw/run.tpl)" \
  {your_container}

得到的结果样例:

docker run \
  --name "/gitlab-runner-4" \
  --runtime "runc" \
  --volume "/srv/gitlab-runner/config:/etc/gitlab-runner" \
  --volume "/var/run/docker.sock:/var/run/docker.sock" \
  --log-driver "json-file" \
  --restart "always" \
  --network "bridge" \
  --env "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
  --detach \
  "gitlab/gitlab-runner:latest" \
  "run" "--user=gitlab-runner" "--working-directory=/home/gitlab-runner"

还有一种方法是使用 https://github.com/lavie/runlike 提供的 pip 包 runlike。使用起来也比较方便,但是输出的结果里面有些参数还得再检查和调整一下。