Question: How do I set up an HTTP proxy for Docker and the Amazon ECS container agent in Amazon Linux?

I want to set up an HTTP proxy for Docker and the Amazon Elastic Container Service (Amazon ECS) container agent in Amazon Linux.

Short descriptionComplete the steps in the following sections:Store the IP address and proxy server portSet up an HTTP proxy for the Docker daemonSet up an HTTP proxy for the Amazon ECS container agentSet up an HTTP proxy for ecs-initNote: You can also set your environment variables during launch using Amazon Elastic Compute Cloud (Amazon EC2) user data with a user data script. For a user data script that works on all versions of Linux, see HTTP proxy configuration.If you're using Amazon Linux 2, see How do I set up an HTTP proxy for Docker and the Amazon ECS container agent in Amazon Linux 2?ResolutionStore the IP address and proxy server port1.    Connect to the Amazon EC2 instance using SSH.2.    As a root user, store the IP address and port of the proxy server for later use in environment variables. For example:export PROXY_SERVER_IP=x.x.x.xexport PROXY_PORT=1234Set up an HTTP proxy for the Docker daemon1.    Run the following commands with sudo permissions:cat <<EOF >> /etc/sysconfig/dockerexport HTTP_PROXY=http://$PROXY_SERVER_IP:$PROXY_PORTexport HTTPS_PROXY=https://$PROXY_SERVER_IP:$PROXY_PORTexport NO_PROXY=169.254.169.254,169.254.170.2EOFNote: HTTP_PROXY is the socket address (IPaddress:Port) of the HTTP proxy that's used to connect the Amazon ECS container agent to the internet.If the HTTP_PROXY variable is set, you must set the NO_PROXY variable to 169.254.169.254,169.254.170.2. This setting filters Amazon EC2 instance metadata, AWS Identity and Access Management (IAM) roles for tasks, and Docker daemon traffic from the proxy.2.    To restart Docker, run the following command:service docker restartNote: The preceding command stops all running containers, including the ecs-agent on the container instance.3.    To verify the HTTP proxy settings for Docker, run the following command:docker info | grep -i proxyNote: The command output shows the HTTP proxy and HTTPS proxy.Set up an HTTP proxy for the Amazon ECS container agent1.    In your /etc/ecs/ecs.config file, append the proxy configuration using the HTTP_PROXY and NO_PROXY agent configuration parameters. For example:cat <<EOF >> /etc/ecs/ecs.configECS_CLUSTER=your-cluster-nameHTTP_PROXY=http://$PROXY_SERVER_IP:$PROXY_PORTNO_PROXY=169.254.169.254,169.254.170.2,/var/run/docker.sockEOF2.    To apply the HTTP proxy configurations from step 1 to the ecs-agent, run the following command:sudo start ecsNote: If you're using an Amazon ECS-optimized Amazon Machine Image (AMI), then the Amazon ECS container agent runs through ecs-init by default.3.    To verify the HTTP proxy settings for Docker and the Amazon ECS container agent, run the following command:docker inspect ecs-agent | grep -i proxyNote: The proxy settings appear in the command output.Set up an HTTP proxy for ecs-initRun the following commands with sudo permissions:cat <<EOF > /etc/init/ecs.overrideenv HTTP_PROXY=$PROXY_SERVER_IP:$PROXY_PORTenv NO_PROXY=169.254.169.254,169.254.170.2,/var/run/docker.sockEOFNote: The configuration for both Docker and the Amazon ECS container agent affects only the current running instance. To update all the instances in a cluster, create a launch configuration with user data, and then use an Auto Scaling group to launch new instances.

Related informationUpdating the Amazon ECS container agentBootstrapping container instances with Amazon EC2 user data