docker容器的ubuntu系统中设置apt-get代理和apt-get源

docker容器的ubuntu系统中设置apt-get代理安装软件

有时候虚拟机不能安装软件,需要设置代理才能正常连接网络安装软件

Ubuntu中给apt-get设置代理
进入docker-haproxy服务
docker exec -it h1 /bin/bash

编辑文件: /etc/apt/apt.conf
在您的apt.conf文件中加入下面这行(根据你的实际情况替换yourproxyaddress和proxyport)
Acquire::http::Proxy "http://yourproxyaddress:proxyport";
Acquire::https::proxy "http://yourproxyaddress:proxyport";

Acquire::http::Proxy "http://10.11.0.148:808";
Acquire::https::proxy "http://10.11.0.148:808";

容器没有编辑器,只能通过echo写入的方式设置代理
设置apt-get的代理
cd /etc/apt
echo 'Acquire::http::Proxy "http://10.11.0.148:808";' >> apt.conf
echo 'Acquire::https::proxy "http://10.11.0.148:808";' >> apt.conf
或者
cd /etc/apt/apt.conf.d
echo 'Acquire::http::Proxy "http://10.11.0.148:808";' >> proxy.conf
echo 'Acquire::https::proxy "http://10.11.0.148:808";' >> proxy.conf

# 系统升级,安装vim编辑器
# apt-get update
root@f9ee51b26ac0:/etc/apt/apt.conf.d# apt-get install vim

# 安装keepalived和ping命令
apt-get install keepalived
apt-get install net-tools
apt-get install iputils-pinp

 

 

aliyun的镜像站

https://developer.aliyun.com/mirror/

ubuntu的香港中文大学源,如果是香港线路可以设置如下

deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty main restricted universe multiverse
deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-security main restricted universe multiverse
deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-updates main restricted universe multiverse
deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty main restricted universe multiverse
deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://ftp.cuhk.edu.hk/pub/Linux/ubuntu/ trusty-backports main restricted universe multiverse

报错
W: GPG error: http://ftp.cuhk.edu.hk/pub/Linux/ubuntu trusty Release:

解决:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 出现的字符串

# apt-get update
# 安装软件
apt-get install iputils-ping --allow-unauthenticated -y


cd /usr/redis/src/
./redis-server ../redis.conf

posted @   reblue520  阅读(1002)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示