从“Docker quickstart终端”启动docker时如何添加`--registry-mirror`?

时间:2015-12-14 06:30:45

标签: configuration proxy docker mirror

来自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 normal启动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'配置文件放到正确的文件中吗?我该怎么办?

2 个答案:

答案 0 :(得分: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&#39; docker-machine可能已经存在(执行docker-machine ls),您可能需要先将其删除(docker-machine rm default:确保您可以轻松地从本地Dockerfiles重新创建图像,和/或您没有&# 39; t有数据容器,需要先保存)

答案 1 :(得分:0)

打开C:\Users\<YourName>\.docker\daemon.json,编辑&#34;注册表镜像&#34;在该文件中输入。

enter image description here

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