【问题标题】:How to add `--registry-mirror` when starting docker from "Docker quickstart terminal"?从“Docker快速启动终端”启动docker时如何添加`--registry-mirror`?
【发布时间】:2015-12-14 06:30:44
【问题描述】:

来自docker分发文档:https://github.com/docker/distribution

上面说要配置docker使用镜像,我们应该:

Configuring the Docker daemon

You will need to pass the --registry-mirror option to your Docker daemon on startup:

docker --registry-mirror=https://<my-docker-mirror-host> daemon

我是 docker 新手,我通过提供的“Docker Quickstart Termial”应用程序从 mac 正常启动 docker,该应用程序实际上调用了 start.sh shell:

#!/bin/bash

VM=default
DOCKER_MACHINE=/usr/local/bin/docker-machine
VBOXMANAGE=/Applications/VirtualBox.app/Contents/MacOS/VBoxManage

BLUE='\033[0;34m'
GREEN='\033[0;32m'
NC='\033[0m'

unset DYLD_LIBRARY_PATH
unset LD_LIBRARY_PATH

clear

if [ ! -f $DOCKER_MACHINE ] || [ ! -f $VBOXMANAGE ]; then
  echo "Either VirtualBox or Docker Machine are not installed. Please re-run the Toolbox Installer and try again."
  exit 1
fi

$VBOXMANAGE showvminfo $VM &> /dev/null
VM_EXISTS_CODE=$?

if [ $VM_EXISTS_CODE -eq 1 ]; then
  echo "Creating Machine $VM..."
  $DOCKER_MACHINE rm -f $VM &> /dev/null
  rm -rf ~/.docker/machine/machines/$VM
  $DOCKER_MACHINE create -d virtualbox --virtualbox-memory 2048 --virtualbox-disk-size 204800 $VM
else
  echo "Machine $VM already exists in VirtualBox."
fi

VM_STATUS=$($DOCKER_MACHINE status $VM)
if [ "$VM_STATUS" != "Running" ]; then
  echo "Starting machine $VM..."
  $DOCKER_MACHINE start $VM
  yes | $DOCKER_MACHINE regenerate-certs $VM
fi

echo "Setting environment variables for machine $VM..."
clear

cat << EOF


                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/


EOF
echo -e "${BLUE}docker${NC} is configured to use the ${GREEN}$VM${NC} machine with IP ${GREEN}$($DOCKER_MACHINE ip $VM)${NC}"
echo "For help getting started, check out the docs at https://docs.docker.com"
echo

eval $($DOCKER_MACHINE env $VM --shell=bash)

USER_SHELL=$(dscl /Search -read /Users/$USER UserShell | awk '{print $2}' | head -n 1)
if [[ $USER_SHELL == *"/bash"* ]] || [[ $USER_SHELL == *"/zsh"* ]] || [[ $USER_SHELL == *"/sh"* ]]; then
  $USER_SHELL --login
else
  $USER_SHELL
fi

我可以将“--registry-mirror”配置放入其中的文件是否正确?我该怎么办?

【问题讨论】:

    标签: configuration proxy docker mirror


    【解决方案1】:

    如果你做一个docker-machine create --help:

    docker-machine create --help
    Usage: docker-machine create [OPTIONS] [arg...]
    
    Create a machine.
    
    Run 'docker-machine create --driver name' to include the create flags for that driver in the help text.
    
    Options:
    ...
       --engine-insecure-registry [--engine-insecure-registry option --engine-insecure-registry option]     Specify insecure registries to allow with the created en
    gine
       --engine-registry-mirror [--engine-registry-mirror option --engine-registry-mirror option]           Specify registry mirrors to use
    

    所以你可以修改你的脚本来增加一个参数:

    --engine-registry-mirror=...
    

    但是,由于您的 'default' docker-machine 可能已经存在(执行docker-machine ls),您可能需要先将其删除(docker-machine rm default:确保您可以轻松地从本地 Dockerfile 重新创建图像,和/或您没有需要首先保存的数据容器)

    【讨论】:

    • 是否可以更新默认机器使用的注册表,而不必(重新)创建一个新的?
    • @Alexis.Rolland 5 年后,我不太相信:这本身就是一个好问题。
    【解决方案2】:

    打开C:\Users\&lt;YourName&gt;\.docker\daemon.json,编辑该文件中的“registry-mirrors”条目。

    {"registry-mirrors":["https://registry.docker-cn.com"],"insecure-registries":[], "debug":true, "experimental": true}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-24
      • 2016-03-04
      • 1970-01-01
      • 2016-11-18
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      • 1970-01-01
      相关资源
      最近更新 更多