给docker配置 HTTP/HTTPS 网络代理

阅读(781)

使用Docker的过程中,因为网络原因,通常需要使用 HTTP/HTTPS 代理来加速镜像拉取、构建和使用。下面是常见的三种场景。

为 dockerd 设置网络代理

“docker pull” 命令是由 dockerd 守护进程执行。而 dockerd 守护进程是由 systemd 管理。因此,如果需要在执行 “docker pull” 命令时使用 HTTP/HTTPS 代理,需要通过 systemd 配置。
为 dockerd 创建配置文件夹。

sudo mkdir -p /etc/systemd/system/docker.service.d

为 dockerd 创建 HTTP/HTTPS 网络代理的配置文件,文件路径是 /etc/systemd/system/docker.service.d/http-proxy.conf 。并在该文件中添加相关环境变量。

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080/"
Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

刷新配置并重启 docker 服务。

sudo systemctl daemon-reload
sudo systemctl restart docker

为 docker 容器设置网络代理

在容器运行阶段,如果需要使用 HTTP/HTTPS 代理,可以通过更改 docker 客户端配置,或者指定环境变量的方式。
更改 docker 客户端配置:创建或更改 ~/.docker/config.json,并在该文件中添加相关配置。

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://proxy.example.com:8080/",
     "httpsProxy": "http://proxy.example.com:8080/",
     "noProxy": "localhost,127.0.0.1,.example.com"
   }
 }
}

指定环境变量:运行 “docker run” 命令时,指定相关环境变量。
环境变量
docker run 示例

HTTP_PROXY
--env HTTP_PROXY="http://proxy.example.com:8080/"
HTTPS_PROXY
--env HTTPS_PROXY="http://proxy.example.com:8080/"
NO_PROXY
--env NO_PROXY="localhost,127.0.0.1,.example.com"

为 docker build 过程设置网络代理

在容器构建阶段,如果需要使用 HTTP/HTTPS 代理,可以通过指定 “docker build” 的环境变量,或者在 Dockerfile 中指定环境变量的方式。
使用 “–build-arg” 指定 “docker build” 的相关环境变量

docker build \
    --build-arg "HTTP_PROXY=http://proxy.example.com:8080/" \
    --build-arg "HTTPS_PROXY=http://proxy.example.com:8080/" \
    --build-arg "NO_PROXY=localhost,127.0.0.1,.example.com"

在 Dockerfile 中指定相关环境变量
环境变量
Dockerfile 示例

HTTP_PROXY
ENV HTTP_PROXY="http://proxy.example.com:8080/"
HTTPS_PROXY
ENV HTTPS_PROXY="http://proxy.example.com:8080/"
NO_PROXY
ENV NO_PROXY="localhost,127.0.0.1,.example.com"

debian国内源提示签名错误

阅读(451)

Debian改换国内源,apt update 提示签名错误。

可以通过更新debian-archive-keyring解决。
安装新版本debian-archive-keyring

sudo apt-get install debian-archive-keyring

Aws Lightsail root登录启动脚本

阅读(644)

创建实例时,如图点击:Add launch script

输入脚本代码:

echo root:urpassword |sudo chpasswd root
sudo sed -i 's/^.*PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;
sudo sed -i 's/^.*PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;
sudo reboot

其中 “urpassword” 是你的密码,也可以创建实例登录后用 passwd 命令设置。

解决xshell无法在vim中复制粘贴

阅读(525)

ssh xshell 连接在vim中无法用 ctrl+insert 复制黏贴
修改.vimrc
set mouse=c
vi的三种模式:命令模式,插入模式,可视模式.鼠标可以启动于各种模式中:
The mouse can be enabled for different modes:

n Normal mode
v Visual mode
i Insert mode
c Command-line mode
h all previous modes when editing a help file
a all previous modes
r for |hit-enter| and |more-prompt| prompt

Normally you would enable the mouse in all four modes with:
:set mouse=a
When the mouse is not enabled, the GUI will still use the mouse for
modeless selection. This doesn’t move the text cursor.

所以配置文件中的set mouse=a启动了所有模式,这样就屏蔽了鼠标右健功能.

vimrc的存放位置:
系统 vimrc 文件:“$VIM/vimrc”
用户 vimrc 文件: “$HOME/.vimrc”
用户 exrc 文件: “$HOME/.exrc”
系统 gvimrc 文件: “$VIM/gvimrc”
用户 gvimrc 文件: “$HOME/.gvimrc”
系统菜单文件:“$VIMRUNTIME/menu.vim”
$VIM 预设值: “/usr/share/vim”

因为/etc/vimrc和~/.vimrc都要被读取,只是~/.vimrc的优先级高。如果~/下没有.vimrc 直接新建一个就好。

宝塔FTP服务Pure-Ftpd读取目录列表失败的解决方法

阅读(609)

宝塔面板在安装了FTP服务“Pure-Ftpd”后,本地使用第三方FTP客户端,提示登录成功,但读取目录列表失败。怀疑是目录权限或端口未开放所致。但经过排查,无论是服务器还是宝塔,都已放行21端口,且目录也出于755权限,均正常。

经过一番探索,发现是Pure-Ftpd开启被动模式后,需要再在服务器放行被动端口。具体方法如下:

  1. 在宝塔面板左侧选择“安全”面板,放行端口21,同时在服务器端也要相应开放此端口;

  2. 开放Pure-Ftpd的被动端口,进入服务器端的防火箱设置页面,放行39000-40000的端口;

  3. 在宝塔面板修改Pure-Ftpd的配置文件。在软件商店找到“Pure-Ftpd”,点击设置。在“配置修改”选项卡中,搜索“ForcePassiveIP”,去掉前面的#号,解除注释。并将后面的IP替换为服务器的外网IP地址。保存配置后,在“服务”选项卡中重载配置即可。

尝试重新登录,看看有什么变化吧!

原文:https://blog.51cto.com/uppower/1404653

Debian改变系统语言环境

阅读(532)

Debian下如何设置语言项,在日常的系统安装中,会存在安装了中文环境后,若是只在终端进行操作时,将会遇到中文错误提示等信息显示为乱码,这时候只要进行语言的切换就可以了。

1.查看当前语言
echo $LANG

2.临时修改服务器语言环境
中文
export LANG="zh_CN.UTF-8"

英文
export LANG="en_US.UTF-8"

3.改变当前用户,永久生效

echo 'LANG="zh_CN.UTF-8"' >> ~/.bashrc
source ~/.bashrc

4.Root修改所有用户,永久生

echo 'LANG="en_US.UTF-8"' >> /etc/profile
source /etc/profile

5.Debian11
可视化修改
sudo dpkg-reconfigure locales

6.CentOS7.x
Root权限编辑/etc/locale.conf文件并保存,然后重新登录终端。
echo 'LANG="en_US.UTF-8"' > /etc/locale.conf

7.CentOS5.x
Root权限编辑/etc/sysconfig/i18n文件并保存,然后重新登录终端。
echo 'LANG="en_US.UTF-8"' > /etc/sysconfig/i18n

8.语言文件读取优先级
~/.bashrc > /etc/profile > /etc/locale.conf,/etc/sysconfig/i18n

使用以下命令查看是否安装成功:
locale -a
然后,重启系统即可。

将frp注册为Windows服务(使用nssm)

阅读(381)

1、下载nssm.exe
官网:http://nssm.cc/download

2、解压至本地目录
根据操作系统选择32位或64位nssm,CD到nssm.exe所在目录

3、服务注册(以注册frpc为例)
命令行输入:

nssm install frpc

接下来会弹出一个框,在path处选择启动frpc的start.bat

点击Install service。

4、服务启动

nssm start frpc

第3和第4步需要管理员权限。如果没有注册工程,尝试在Arguments填入:AppNoConsole=1。
启动后,你将在本地计算机服务列表看到frpc服务。Win+R,services.msc。

其他命令:

nssm start <servicename> //启动创建的servername服务
nssm stop <servicename> //停止创建的servername服务
nssm restart <servicename> //重新启动创建的servername服务
nssm remove <servername> //删除创建的servername服务

github hosts

阅读(292)

# update: 20221004
# Github Hosts
# domain: github.com

140.82.114.4 github.com
140.82.114.9 nodeload.github.com
140.82.112.5 api.github.com
140.82.112.10 codeload.github.com
185.199.108.133 raw.github.com
185.199.108.153 training.github.com
185.199.108.153 assets-cdn.github.com
185.199.108.153 documentcloud.github.com
140.82.114.17 help.github.com

# domain: githubstatus.com
185.199.108.153 githubstatus.com

# domain: fastly.net
199.232.69.194 github.global.ssl.fastly.net

# domain: githubusercontent.com
185.199.108.133 raw.githubusercontent.com
185.199.108.154 pkg-containers.githubusercontent.com
185.199.108.133 cloud.githubusercontent.com
185.199.108.133 gist.githubusercontent.com
185.199.108.133 marketplace-screenshots.githubusercontent.com
185.199.108.133 repository-images.githubusercontent.com
185.199.108.133 user-images.githubusercontent.com
185.199.108.133 desktop.githubusercontent.com
185.199.108.133 avatars.githubusercontent.com
185.199.108.133 avatars0.githubusercontent.com
185.199.108.133 avatars1.githubusercontent.com
185.199.108.133 avatars2.githubusercontent.com
185.199.108.133 avatars3.githubusercontent.com
185.199.108.133 avatars4.githubusercontent.com
185.199.108.133 avatars5.githubusercontent.com
185.199.108.133 avatars6.githubusercontent.com
185.199.108.133 avatars7.githubusercontent.com
185.199.108.133 avatars8.githubusercontent.com
# End of the section