如何在docker-compose中使用本地代理设置 [英] How to use local proxy settings in docker-compose

查看:2459
本文介绍了如何在docker-compose中使用本地代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于旧的安装是手工完成的,因此我正在为Redmine安装设置新的服务器,这使得很难正确地更新所有内容。我决定使用Docker映像,但是由于错误消息而无法启动Docker容器。主机在代理服务器后面运行,我认为这是导致此问题的原因,因为其他所有功能(例如wget,curl等)都可以正常工作。

I am setting up a new server for our Redmine installation, since the old installation was done by hand, which makes it difficult to update everything properly. I decided to go with a Docker image but am having trouble starting the docker container due to an error message. The host is running behind a proxy server, which I think, is causing this problem, as everything else such as wget, curl, etc. is working fine.

错误消息:

Pulling redmine (redmine:)...
ERROR: Get https://registry-1.docker.io/v2/: dial tcp 34.206.236.31:443: connect: connection refused

我在Google关于在后台将Docker / Docker-Compose与代理服务器一起使用的情况,并发现了一些人们遇到相同问题的网站,但这些网站都没有真正帮助我解决我的问题。

I searched on Google about using Docker/Docker-Compose with a proxy server in the background and found a few websites where people had the same issue but none of these really helped me with my problem.

我检查了Docker文档并找到了指南,但这似乎对我不起作用: https: //docs.docker.com/network/proxy/

I checked with the Docker documentation and found a guide but this does not seem to work for me: https://docs.docker.com/network/proxy/

我也在StackOverflow上找到了一个已回答的问题:在docker-compose上使用代理在服务器中,这可能是我想要的解决方案,但是我不确定该将解决方案放在哪里。我猜这个人的意思是docker-compose.yml文件,但是我可能错了。

I also found an answered question here on StackOverflow: Using proxy on docker-compose in server which might be the solution I am after but I am unsure where exactly I have to put the solution. I guess the person means the docker-compose.yml file but I could be wrong.

这就是我的docker-compose.yml样子:

This is what my docker-compose.yml looks like:

version: '3.1'

services:

redmine:
 image: redmine
 restart: always
 ports:
   - 80:3000
 environment:
   REDMINE_DB_MYSQL: db
   REDMINE_DB_PASSWORD: SECRET_PASSWORD

db:
image: mysql:5.7
restart: always
environment:
  MYSQL_ROOT_PASSWORD: SECRET_PASSWORD
  MYSQL_DATABASE: redmine

我希望运行以下命令而不会出现上述错误消息

I expect to run the following command without the above error message

docker-compose -f docker-compose.yml up -d


推荐答案

我做了更多的研究,并且似乎使用了更好的关键词,因为我现在找到了解决方案。我想与所有人共享该解决方案,以防其他人可能需要它。

I did a bit more research and seem to have used better key words because I found my solution now. I wanted to share the solution with everyone, in case someone else may ever need it.


  • 创建用于通过systemd配置docker服务的文件夹

  • Create folder for configuring docker service through systemd

mkdir /etc/systemd/system/docker.service.d

/etc/systemd/system/docker.service.d/http-proxy.conf 中创建服务配置文件,并将以下内容放入新创建的文件

Create service configuration file at /etc/systemd/system/docker.service.d/http-proxy.conf and put the following in the newly created file

[Service]
 # NO_PROXY is optional and can be removed if not needed
 # Change proxy_url to your proxy IP or FQDN and proxy_port to your proxy port
 # For Proxy server which require username and password authentication, just add the proper username and password to the URL. (see example below)

 # Example without authentication
 Environment="HTTP_PROXY=http://proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"

 # Example with authentication
 Environment="HTTP_PROXY=http://username:password@proxy_url:proxy_port" "NO_PROXY=localhost,127.0.0.0/8"



  • 重新加载systemctl以便读取新设置

    • Reload systemctl so that new settings are read

      sudo systemctl daemon-reload

      验证docker服务环境是否为正确设置

      Verify that docker service Environment is properly set

      sudo systemctl show docker --property Environment

      重新启动docker服务,使其使用更新的环境设置

      Restart docker service so that it uses updated Environment settings

      sudo systemctl重新启动docker

      现在,您可以在计算机上执行 docker-compose 命令,而无需获取任何连接被拒绝错误消息。

      Now you can execute the docker-compose command on your machine without getting any connection refused error messages.

      这篇关于如何在docker-compose中使用本地代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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