when I run a Jenkins build, my back-end code is not updating in AWS. There seems to be an error when I try to build the Elastic Beanstalk:
Encountered error starting new ECS task: { "failures": [ { "reason": "RESOURCE:PORTS", "arn": "arn:aws:ecs:eu-west-1:863820595425:container-instance/d6b92955-eb16-4911-b874-683155fcd630" } ], "tasks": [] }
Has anyone encountered this before? The port set up in the dockerrun.aws.json file has not been changed in over a year. If I manually restart Task Definitions this backend will eventually update but I need to see why the Ports issue is happening.
My dockerrrun.aws.json file:
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "customerportal-backend",
"image": "<AWS_ACCOUNT_ID>.dkr.ecr.eu-west-1.amazonaws.com/<ECR_REPO_NAME>:latest",
"essential": true,
"memory": 1024,
"portMappings": [
{
"hostPort": 80,
"containerPort": 3001
}
],
"mountPoints": [
{
"sourceVolume": "store-efs",
"containerPath": "/efs-mount-point"
}
],
"links": [
"clamav-rest"
]
},
{
"name": "clamav-server",
"image": "mkodockx/docker-clamav:latest",
"essential": true,
"memory": 1536
},
{
"name": "clamav-rest",
"image": "lokori/clamav-rest",
"essential": true,
"memory": 1024,
"links": [
"clamav-server:clamav-server"
],
"portMappings": [
{
"hostPort": 3100,
"containerPort": 8080
}
],
"environment" : [
{ "name" : "CLAMD_HOST", "value" : "clamav-server" }
]
}
],
"volumes": [
{
"name" : "store-efs",
"host": {
"sourcePath": "/var/app/efs"
}
}
]
}
Related
I tried to run Multicontainer Docker in AWS Elastic Beanstalk. Here is my Dockerrun.aws.json
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"command": ["python", "manage.py", "runserver", "0.0.0.0:8000"
],
"environment": [
{
"name": "JAEGER_AGENT_HOST",
"value": "jaeger"
},
{
"name": "STOREFRONT_URL",
"value": "http://localhost:3000/"
},
{
"name": "DASHBOARD_URL",
"value": "http://localhost:9000/"
}
],
"memory": 512,
"image": "saleor-platform_api",
"essential": true,
"links": [
"api",
"POSTGRES_USER",
"redis",
"worker",
"jaeger"
],
"mountPoints": [
{
"containerPath": "/app/tests",
"sourceVolume": "_SaleorTests"
},
{
"containerPath": "/app/media",
"sourceVolume": "Saleor-Media"
},
{
"containerPath": "/app/saleor",
"sourceVolume": "_Saleor"
},
{
"containerPath": "/app/templates",
"sourceVolume": "Saleor-templates"
}
],
"name": "api",
"portMappings": [
{
"containerPort": 8000,
"hostPort": 8000
}
]
},
{
"environment": [
{
"name": "POSTGRES_USER",
"value": "saleor"
},
{
"name": "POSTGRES_PASSWORD",
"value": "saleor"
}
],
"essential": true,
"memory": 256,
"image": "library/postgres:11.1-alpine",
"links": [
"api",
"POSTGRES_USER",
"redis",
"worker",
"jaeger"
],
"mountPoints": [
{
"containerPath": "/var/lib/postgresql",
"sourceVolume": "Saleor-Db"
}
],
"name": "db",
"portMappings": [
{
"containerPort": 5432,
"hostPort": 5432
}
]
},
{
"essential": true,
"image": "jaegertracing/all-in-one",
"name": "jaeger",
"memory": 256,
"links": [
"api",
"POSTGRES_USER",
"redis",
"worker",
"jaeger"
],
"portMappings": [
{
"containerPort": 5775,
"hostPort": 5775,
"protocol": "udp"
},
{
"containerPort": 6831,
"hostPort": 6831,
"protocol": "udp"
},
{
"containerPort": 6832,
"hostPort": 6832,
"protocol": "udp"
},
{
"containerPort": 5778,
"hostPort": 5778
},
{
"containerPort": 16686,
"hostPort": 16686
},
{
"containerPort": 14268,
"hostPort": 14268
},
{
"containerPort": 9411,
"hostPort": 9411
}
]
},
{
"essential": true,
"image": "library/redis:5.0-alpine",
"memory": 256,
"links": [
"api",
"POSTGRES_USER",
"redis",
"worker",
"jaeger"
],
"mountPoints": [
{
"containerPath": "/data",
"sourceVolume": "Saleor-Redis"
}
],
"name": "redis",
"portMappings": [
{
"containerPort": 6379,
"hostPort": 6379
}
]
},
{
"command": [
"celery",
"-A",
"saleor",
"worker",
"--app=saleor.celeryconf:app",
"--loglevel=info"
],
"image": "saleor-platform_worker",
"memory": 256,
"essential": true,
"links": [
"api",
"POSTGRES_USER",
"redis",
"worker",
"jaeger"
],
"mountPoints": [
{
"containerPath": "/app/media",
"sourceVolume": "Saleor-Media"
}
],
"name": "worker"
}
],
"family": "",
"volumes": [
{
"host": {
"sourcePath": "./saleor/saleor/"
},
"name": "_Saleor"
},
{
"host": {
"sourcePath": "./saleor/templates/"
},
"name": "Saleor-templates"
},
{
"host": {
"sourcePath": "./saleor/tests/"
},
"name": "_SaleorTests"
},
{
"host": {
"sourcePath": "saleor-media"
},
"name": "Saleor-Media"
},
{
"host": {
"sourcePath": "saleor-db"
},
"name": "Saleor-Db"
},
{
"host": {
"sourcePath": "saleor-redis"
},
"name": "Saleor-Redis"
}
]
}
However, when I typed "eb local run", it gives me the error "ERROR: ValidationError - The AWSEBDockerrunVersion key in the Dockerrun.aws.json file is not valid or is not included."
Does anyone know why? Thanks
Based on the comments.
The issue was that a EB Docker platform was incorrect and/or not chosen.
The solution was to select a correct platform using:
eb platform select
My current approach:
The Dockerrun.aws.json file looks like this:
{
"AWSEBDockerrunVersion": 2,
"volumes": [
{
"name": "mysql-volume",
"host": {
"sourcePath": "/var/app/current/web-app"
}
}
],
"containerDefinitions": [
{
"name": "mysql",
"image": "mysql:5.7",
"environment": [
{
"name": "MYSQL_ROOT_PASSWORD",
"value": "root"
},
{
"name": "MYSQL_USER",
"value": "user"
},
{
"name": "MYSQL_PASSWORD",
"value": "pass"
},
{
"name": "MYSQL_DATABASE",
"value": "db"
}
],
"essential": true,
"memory": 256,
"portMappings": [
{
"hostPort": 3306,
"containerPort": 3306
}
],
"mountPoints": [
{
"sourceVolume": "mysql-volume",
"containerPath": "/var/lib/mysql"
}
]
},
{
"name": "web-application",
"image": "some image",
"essential": true,
"memory": 512,
"portMappings": [
{
"hostPort": 80,
"containerPort": 8080
}
],
"links": [
"mysql"
]
}
]
}
When I connect via SSH to EC2 instance I see that no volumes are created. Not sure, what's the reason and how can I change the Dockerrrun.aws.json file to make it work. Also, when I stop and restart the instance the data is lost
I have the need to find the hostname of my ECS task via the CLI, which according to the Amazon documentation should be available via the CLI:
https://docs.aws.amazon.com/cli/latest/reference/ecs/describe-task-definition.html
However, when I run the describe-task-definition it is not returning the information:
> aws ecs describe-task-definition --task-definition my-test-task:1
{
"taskDefinition": {
"status": "ACTIVE",
"networkMode": "bridge",
"family": "my-test-task",
"placementConstraints": [],
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
}
],
"volumes": [
{
"host": {
"sourcePath": "/opt/cf/rails-app/public/"
},
"name": "ruby-on-rails-public-volume"
}
],
"taskDefinitionArn": "arn:aws:ecs:us-east-1:accountId:task-definition/my-test-task:1",
"containerDefinitions": [
{
"memoryReservation": 1024,
"environment": [
{
"name": "DATABASE_HOSTNAME",
"value": "hostname"
},
{
"name": "PUMA_WORKERS",
"value": "2"
},
{
"name": "RAILS_ENV",
"value": "staging"
},
{
"name": "DATABASE_NAME",
"value": "ruby-on-rails"
},
{
"name": "DEBIAN_FRONTEND",
"value": "noninteractive"
},
{
"name": "PORT",
"value": "8080"
},
{
"name": "LANG",
"value": "en_US.UTF-8"
},
{
"name": "DATABASE_PASSWORD",
"value": "cf"
},
{
"name": "DATABASE_USER",
"value": "cf"
},
{
"name": "PUMA_MAX_THREADS",
"value": "6"
}
],
"name": "my-test-task",
"mountPoints": [
{
"sourceVolume": "ruby-on-rails-public-volume",
"containerPath": "/opt/cf/rails-app/public/"
}
],
"image": "accountId.dkr.ecr.us-east-1.amazonaws.com/cf/rails:latest",
"cpu": 1024,
"portMappings": [
{
"protocol": "tcp",
"containerPort": 8080,
"hostPort": 8080
}
],
"command": [
"puma",
"-C",
"config/puma.rb"
],
"essential": true,
"volumesFrom": []
}
],
"revision": 1
}
}
I am not sure what I need to do to get that value included. I confirmed I am running the latest CLI.
Thanks!
First of all the hoostname is not defined to task definition. Its defined to container definition inside task definition. Secondly, There is no default hostname, You have to explicitly define the hostname in the container definition while creating task definition revision. By default, it uses container id as the hostname.
I am trying to run service with following definition on AWS ECS cluster. But I am getting an error. Invalid 'volumesFrom' setting. Unknown container: 'docker-data'. I have separately launched docker-data service but my other service is still unable to find my data container. Below are task definitions.
{
"containerDefinitions": [{
"name": "docker-data",
"image": "jaigouk/data-only-container",
"memory": 128
}],
"family": "docker-data"
}
{
"containerDefinitions": [{
"image": "my/work-image",
"name": "image2",
"memory": 512,
"portMappings": [{
"hostPort": 8040,
"containerPort": 8040,
"protocol": "tcp"
}],
"volumesFrom": [{
"sourceContainer": "docker-data"
}]
}],
"family": "console"
}
Looks like you're defining 2 containers in two task definitions. In this case, docker-data is not known.
Here is one of my working example
{
"taskDefinitionArn":"arn:aws:ecs:ap-southeast-1:xxxx:task-definition/vc-p-tim:15",
"networkMode":"bridge",
"status":"ACTIVE",
"revision":15,
"taskRoleArn":null,
"containerDefinitions":[
{
"volumesFrom":[
],
"memory":2048,
"extraHosts":null,
"dnsServers":null,
"disableNetworking":null,
"dnsSearchDomains":null,
"hostname":null,
"essential":true,
"entryPoint":null,
"mountPoints":[
{
"containerPath":"/apps",
"sourceVolume":"tinymce-data",
"readOnly":null
}
],
"name":"tim-srv",
"ulimits":null,
"dockerSecurityOptions":null,
"environment":[
],
"links":null,
"workingDirectory":null,
"readonlyRootFilesystem":null,
"image":"xxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/tinymce-server:latest",
"command":null,
"user":null,
"dockerLabels":null,
"logConfiguration":null,
"cpu":0,
"privileged":null,
"memoryReservation":null
},
{
"volumesFrom":[
{
"readOnly":null,
"sourceContainer":"tim-srv"
}
],
"memory":256,
"extraHosts":null,
"dnsServers":null,
"disableNetworking":null,
"dnsSearchDomains":null,
"hostname":null,
"essential":true,
"entryPoint":null,
"mountPoints":[
],
"name":"tim-api",
"ulimits":null,
"dockerSecurityOptions":null,
"links":null,
"workingDirectory":null,
"readonlyRootFilesystem":null,
"image":"xxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/tinymce-api:0118171510",
"command":null,
"user":null,
"dockerLabels":null,
"logConfiguration":null,
"cpu":0,
"privileged":null,
"memoryReservation":null
}
],
"volumes":[
{
"host":{
"sourcePath":"tinymce-data"
},
"name":"tinymce-data"
}
],
"family":"vc-p-tim"
}
But to run the
aws ecs register-task-definition --family --container-definitions wordpress file: //wordpress.json"
is giving the following error below:
Error parsing parameter '--container-definitions': Invalid JSON: Expecting object: line 1 column 1 (char 0)
JSON received: {
My wordpress.json:
{
"containerDefinitions": [
{
"name": "wordpress",
"links": [
"mysql"
],
"image": "wordpress",
"essential": true,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80
}
],
"memory": 500,
"cpu": 10
},
{
"environment": [
{
"name": "MYSQL_ROOT_PASSWORD",
"value": "password"
}
],
"name": "mysql",
"image": "mysql",
"cpu": 10,
"memory": 500,
"essential": true
}
],
"family": "wordpress"
}
Any suggestions?
The correct aws cli command for registration of the Task is
aws ecs register-task-definition --cli-input-json file://wordpress.json