Bobcares

Set up HTTP proxy for Docker and ECS container agent: Amazon EC2

by | Aug 18, 2021

Wondering how to set up an HTTP proxy for Docker and ECS container agent? We can help you with this!

Here, at Bobcares, we often receive similar requests from our AWS customers as a part of our AWS Support Services.

Today, let’s see the steps followed by our Support Techs to help our customers to set up an HTTP proxy for Docker and ECS container agents.
 

Set up an HTTP proxy for Docker and ECS container agent

 
Let’s see the steps to set up an HTTP proxy for Docker and ECS container agents in Amazon Linux:

  1. At first, we have to store the IP address and proxy server port.
  2. Then, we need to set up an HTTP proxy for the Docker.
  3. The next step is to set up an HTTP proxy for the Amazon ECS container agent to connect to the internet.
  4. And finally, we need to set up an HTTP proxy for ecs-init

 

Storing the IP address and proxy server port

 

  1. Firstly, access the EC2 instance via SSH.

2. Switch to root user and then store the IP address and port of the proxy server. For example, see the following:

# export PROXY_SERVER_IP=x.x.x.x
# export PROXY_PORT=9876

 

Set up an HTTP proxy for the Docker

 

  1. To set up the HTTP proxy for the Docker daemon, run the following command:
# cat <<EOF >> /etc/sysconfig/docker
>export HTTP_PROXY=http://$PROXY_SERVER_IP:$PROXY_PORT
>export HTTPS_PROXY=https://$PROXY_SERVER_IP:$PROXY_PORT
>export NO_PROXY=169.254.169.254,169.254.170.2
>EOF

Here, HTTP_PROXY is the socket address of the HTTP proxy that’s used to connect the Amazon ECS container agent to the internet. Also, we must set the NO_PROXY variable to 169.254.169.254,169.254.170.2, and this setting filters EC2 instance metadata, AWS Identity, and Access Management (IAM) roles for tasks, and Docker daemon traffic from the proxy.

2. Restart Docker and while restarting the docker using the following command will stop all running containers including the ecs-agent on the container instance.

# service docker restart

3. Run the following command to verify HTTP proxy settings for Docker daemon.

# docker info | grep -i proxy
HTTP proxy:  http://x.x.x.x:9876
HTTPS proxy:  http://x.x.x.x:9876
NO proxy:  169.254.169.254,169.254.170.2

 

Set up an HTTP proxy for the Amazon ECS container agent to connect to the internet

 

  1. Now include the proxy configuration using the HTTP_PROXY and NO_PROXY agent configuration parameters in the ECS configuration file, /etc/ecs/ecs.config.
#cat <<EOF >> /etc/ecs/ecs.config
>ECS_CLUSTER=cluster-name
>HTTP_PROXY=http://$PROXY_SERVER_IP:$PROXY_PORT
>NO_PROXY=169.254.169.254,169.254.170.2,/var/run/docker.sock
>EOF

2. Then start the ECS agent to apply the proxy configuration to the agent .

# sudo start ecs

By default, the Amazon ECS container agent runs through ecs-init if we are using an Amazon ECS-optimized AMI.

3. We can run the following command to verify the HTTP proxy settings for Docker and the ECS agent.

# docker inspect ecs-agent | grep -i proxy
"HTTP_PROXY=http://x.x.x.x:9876",
"NO_PROXY=169.254.169.254,169.254.170.2,/var/run/docker.sock"

 

Set up an HTTP proxy for ecs-init

 
The last step is to set the HTTP proxy for ecs-init communication. Run the following command:

# cat <<EOF > /etc/init/ecs.override
>env HTTP_PROXY=$PROXY_SERVER_IP:$PROXY_PORT
>env NO_PROXY=169.254.169.254,169.254.170.2,/var/run/docker.sock
>EOF

This configuration of the Amazon ECS container agent and the Docker daemon affects all the currently running instances.

Also, note that we can also set the environment variables while launching by using Amazon EC2 user data with a user data script.

[Need help with more AWS queries? We’d be happy to assist]
 

Conclusion

 
To conclude, today we discussed the steps followed by our Support Engineers to help our customers to set up an HTTP proxy for Docker and ECS container agents.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF