如何从“Docker quickstart终端”启动docker时添加`--registry-mirror'? [英] How to add `--registry-mirror` when starting docker from "Docker quickstart terminal"?

查看:1464
本文介绍了如何从“Docker quickstart终端”启动docker时添加`--registry-mirror'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

 配置Docker守护程序

启动时需要将--registry-mirror选项传递给Docker守护进程:

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

我是docker的新手,我通过提供的Docker Quickstart Termal应用程序,其动作调用 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

清除

如果[! -f $ DOCKER_MACHINE] || [! -f $ VBOXMANAGE];然后
echo没有安装VirtualBox或Docker Machine,请重新运行Toolbox安装程序,然后重试。
exit 1
fi

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

if [$ VM_EXISTS_CODE -eq 1];然后
echo正在创建机器$ 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
echoMachine $ VM已经存在于VirtualBox中。
fi

VM_STATUS = $($ DOCKER_MACHINE status $ VM)
if [$ VM_STATUS!=Running];然后
echo正在启动机器$ VM ...
$ DOCKER_MACHINE start $ VM
是| $ DOCKER_MACHINE regenerate-certs $ VM
fi

echo设置机器的环境变量$ VM ...
clear

cat< ; EOF


##。
## ## ## ==
## ## ## ## ===
/ \ ___ / ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~〜/ === - ~~~
\ ______ o __ /
\ \ __ /
\ ____ \ _______ /


EOF
echo -e$ {BLUE} docker $ { NC}配置为使用带有IP $ {GREEN} $($ DOCKER_MACHINE ip $ VM)的$ {GREEN} $ VM $ {NC}机器$ {NC}
echo文档在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

如果你做一个 docker-machine create - >

-help

  docker-machine create --help 
用法:docker-machine create [OPTIONS] [arg ...]

创建一台机器。

运行'docker-machine create --driver name',在帮助文本中包含该驱动程序的创建标志。

选项:
...
--engine-insecure-registry [--engine-insecure-registry选项--engine-insecure-registry选项]指定不安全的注册表允许使用创建的en
gine
--engine-registry-mirror [--engine-registry-mirror选项--engine-registry-mirror选项]指定要使用的注册表镜像

因此,您可以修改脚本以添加一个参数:

   -  engine-registry-mirror = ... 

,因为你的默认'docker-machine可能已经存在了(做一个 docker-machine ls ),你可能需要首先删除它( docker-machine rm default :确保您可以轻松地从本地Dockerfiles重新创建映像,和/或没有数据容器需要先保存)


From the docker distribution document: https://github.com/docker/distribution

It says to configure the docker to use the mirror, we should:

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

I'm newbie to docker, and I start docker from mac normal by the provided "Docker Quickstart Termial" app, which actaully invokes a 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

Is it the correct file that I can put my '--registry-mirror' config to it? What should I do?

解决方案

If you do a 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

So you can modify your script to add one more parameter:

--engine-registry-mirror=...

However, since your 'default' docker-machine probably already exists (do a docker-machine ls), you might need to remove it first (docker-machine rm default: make sure you can easily recreate your images from your local Dockerfiles, and/or that you don't have data container that would need to be saved first)

这篇关于如何从“Docker quickstart终端”启动docker时添加`--registry-mirror'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆