1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ECSのDockerコンテナにコマンド実行メモ

Last updated at Posted at 2019-05-11
# クラスタ名からEC2インスタンスIDを取得
CLS=sample-cluster
instanceID=$(aws ecs describe-container-instances --cluster $CLS --container-instances "$(aws ecs list-container-instances --cluster $CLS --query containerInstanceArns)" --query "containerInstances[].ec2InstanceId" --output text)

# インスタンスIDからパブリックIP取得
publicIp=$(aws ec2 describe-instances --instance-ids $instanceID --query "Reservations[].Instances[].NetworkInterfaces[].PrivateIpAddresses[].Association.PublicIp" --output text)

# ECSのコンテナに対してdocker exec経由でコマンドを実行
ssh ec2-user@$publicIp docker exec \$\(docker ps --filter ancestor=999999999999.dkr.ecr.ap-northeast-1.amazonaws.com/sample:latest --format "{{.ID}}"\) ls
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?