Menu
Amazon EC2 Container Service
Developer Guide (API Version 2014-11-13)

HTTP Proxy Configuration

To configure your Amazon ECS container agent to use an HTTP proxy, set the following variables in the /etc/ecs/ecs.config, /etc/init/ecs.override, and /etc/sysconfig/docker files at launch time (with Amazon EC2 user data), or manually edit the configuration file and restart the agent afterwards:

/etc/ecs/ecs.config and /etc/init/ecs.override
HTTP_PROXY=10.0.0.131:3128

Set this value to the hostname (or IP address) and port number of an HTTP proxy to use for the ECS agent to connect to the Internet. For example, your container instances may not have external network access through an Amazon VPC Internet gateway, NAT gateway, or instance.

NO_PROXY=169.254.169.254,169.254.170.2,/var/run/docker.sock

Set this value to 169.254.169.254,169.254.170.2,/var/run/docker.sock to filter EC2 instance metadata, IAM roles for tasks, and Docker daemon traffic from the proxy.

/etc/sysconfig/docker
HTTP_PROXY=10.0.0.131:3128

Set this value to the hostname (or IP address) and port number of an HTTP proxy to use for the Docker daemon to connect to the Internet. For example, your container instances may not have external network access through an Amazon VPC Internet gateway, NAT gateway, or instance.

NO_PROXY=169.254.169.254

Set this value to 169.254.169.254 to filter EC2 instance metadata from the proxy.

The above variables only affect the Amazon ECS container agent, ecs-init, and the Docker daemon; they do not configure Docker or any other services (such as yum) to use the proxy.

Example HTTP proxy user data script

The example user data cloud-boothook script below configures the Amazon ECS container agent, the Docker daemon, and yum to use an HTTP proxy that you specify. You can also specify a cluster into which the container instance will register itself.

To use this script when you launch a container instance, follow the steps in Launching an Amazon ECS Container Instance, and in Step 10. Then, copy and paste the cloud-boothook script below into the User data field (be sure to substitute the red example values with your own proxy and cluster information).

Copy
#cloud-boothook # Configure Yum, the Docker daemon, and the ECS agent to use an HTTP proxy # Specify proxy host, port number, and ECS cluster name to use PROXY_HOST=10.0.0.131 PROXY_PORT=3128 CLUSTER_NAME=proxy-test # Set Yum HTTP proxy if [ ! -f /var/lib/cloud/instance/sem/config_yum_http_proxy ]; then echo "proxy=http://$PROXY_HOST:$PROXY_PORT" >> /etc/yum.conf echo "$$: $(date +%s.%N | cut -b1-13)" > /var/lib/cloud/instance/sem/config_yum_http_proxy fi # Set Docker HTTP proxy if [ ! -f /var/lib/cloud/instance/sem/config_docker_http_proxy ]; then echo "export HTTP_PROXY=http://$PROXY_HOST:$PROXY_PORT/" >> /etc/sysconfig/docker echo "NO_PROXY=169.254.169.254" >> /etc/sysconfig/docker echo "$$: $(date +%s.%N | cut -b1-13)" > /var/lib/cloud/instance/sem/config_docker_http_proxy fi # Set ECS agent HTTP proxy if [ ! -f /var/lib/cloud/instance/sem/config_ecs-agent_http_proxy ]; then echo "ECS_CLUSTER=$CLUSTER_NAME" >> /etc/ecs/ecs.config echo "HTTP_PROXY=$PROXY_HOST:$PROXY_PORT" >> /etc/ecs/ecs.config echo "NO_PROXY=169.254.169.254,169.254.170.2,/var/run/docker.sock" >> /etc/ecs/ecs.config echo "$$: $(date +%s.%N | cut -b1-13)" > /var/lib/cloud/instance/sem/config_ecs-agent_http_proxy fi