AWS Elasticbeanstalk Docker Errors Deploying - amazon-web-services

I have been playing with the Dockerrun.aws.json file and I can't figure out how it should work. I am new to AWS Docker config stuff and just need the communities help with this.
Everytime I deploy to the docker image to Elastic Beanstalk I get this error.
[2017-12-19T19:38:40.877Z] ERROR [31251] : Command CMD-AppDeploy failed!
[2017-12-19T19:38:40.879Z] INFO [31251] : Command processor returning results:
{"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"(TRUNCATED)...spec \":\": invalid volume specification: ':'.\nSee 'docker run --help'.\nFailed to run Docker container: docker: Error response from daemon: invalid volume spec \":\": invalid volume specification: ':'.\nSee 'docker run --help'.. Check snapshot logs for details. \nHook /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI","returncode":125,"events":[{"msg":"Successfully pulled image:latest","severity":"TRACE","timestamp":1513712291},{"msg":"Successfully built aws_beanstalk/staging-app","severity":"TRACE","timestamp":1513712317},{"msg":"Failed to run Docker container: docker: Error response from daemon: invalid volume spec \":\": invalid volume specification: ':'.\nSee 'docker run --help'.. Check snapshot logs for details.","severity":"ERROR","timestamp":1513712320}]}],"truncated":"true"}
....
[2017-12-19T19:48:57.688Z] ERROR [31884] : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError)
caused by: 5503805a9751c924331669930c577b50628d1d0967015c301671f151e207312e
Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Tue Dec 19 19:48:57 UTC 2017:
/bin/sh: 1: Syntax error: "(" unexpected. Check snapshot logs for details. (ElasticBeanstalk::ExternalInvocationError)
caused by: 5503805a9751c924331669930c577b50628d1d0967015c301671f151e207312e
Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Tue Dec 19 19:48:57 UTC 2017:
/bin/sh: 1: Syntax error: "(" unexpected. Check snapshot logs for details. (Executor::NonZeroExitStatus)
My Dockerrun.aws.json file
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "path/to/image:latest",
"Update": "true"
},
"Authentication": {
"Bucket": "mybucket",
"Key": "dockercfg"
},
"Ports": [
{
"ContainerPort": "80"
}
],
"Volumes": []
}
Dockerfile
FROM node:latest
WORKDIR /app
ADD package.json /app
RUN npm i --production
ADD . /app
RUN node ./node_modules/grunt/bin/grunt prod
CMD npm start
EXPOSE 80
I appreciate any help I can get on this issue. I am hitting a wall on this.
Thanks.

Related

Unable to access jarfile - Docker on Elastic Beanstalk

I am trying to deploy a Docker image of a Spring Boot application to AWS Elastic Beanstalk and I'm encountering this error in /var/log/eb-activity.log:
Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Wed Jun 22 11:56:25 UTC 2016:
Error: Unable to access jarfile /home/packedit/app/packed-it.jar. Check snapshot logs for details. (Executor::NonZeroExitStatus)
This is a single container on Elastic Beanstalk with the following Dockerrun.aws.json:
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "packedit/packedit-api",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "8080"
}
],
"Volumes": [
{
"HostDirectory": "/var/app/packedit",
"ContainerDirectory": "/home/packedit/app"
}
],
"Logging": "/home/packedit/app/logs"
}
This is the Dockerfile:
FROM java:8
MAINTAINER my#email.com
VOLUME /tmp
EXPOSE 8080
ENV USER_NAME packedit
ENV APP_HOME /home/$USER_NAME/app
ENV APP_FILENAME packed-it.jar
RUN useradd -ms /bin/bash $USER_NAME
RUN mkdir -p $APP_HOME/data
ADD $APP_FILENAME $APP_HOME/$APP_FILENAME
RUN chown -R $USER_NAME $APP_HOME/
USER $USER_NAME
WORKDIR $APP_HOME
RUN bash -c 'touch $APP_FILENAME'
# Can't use $APP_FILENAME here because ENTRYPOINT does not do ENV replacement
# See: http://stackoverflow.com/a/28854410/336752
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","packed-it.jar"]
I have successfully deployed the Docker image to an EC2 instance using ECS but I have not succeeded with Elastic Beanstalk. My guess is that I am doing something wrong with the volumes but I am struggling to understand the documentation. I originally started with a multicontainer configuration but have simplified to try and isolate my issue.
Thanks for any advice.
You need to remove the line
"ContainerDirectory": "/home/packedit/app"
from your Dockerrun.aws.json.
It seems like the confusion is with how docker volumes work. The volumes are allocated at runtime and persist on consecutive runs on the same machine.
Here is what is happening. The docker image is built with jar in /home/packedit/app but since you have defined a volume in the same location, an empty volume is created when it is run and mounted in that location. Hence, the same directory of the image is ignored.
Here is how you can reproduce the issue locally:
docker build .
docker run -v /home/packedit/app IMAGEID_FROM_OUTPUT_OF_PREVIOUS_COMMAND

Error Deploying Docker Container to Elastic Beanstalk

I'm using Elastic Beanstalk to deploy a Docker Image I've created. I created a .zip file with a Dockerfile and Dockerrun.aws.json file.
When I deploy, I get the following error:
[2015-11-02T18:08:30.366Z] ERROR [4515] : Command execution failed: Activity failed. (ElasticBeanstalk::ActivityFatalError) caused by: jq: error: Cannot iterate over null ab6ac43aeaf75fb000d02a1fee73e829a92cef629bad46e6b727dc967f837b54
Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Mon Nov 2 18:08:30 UTC 2015:. Check snapshot logs for details. (ElasticBeanstalk::ExternalInvocationError) caused by: jq: error: Cannot iterate over null ab6ac43aeaf75fb000d02a1fee73e829a92cef629bad46e6b727dc967f837b54
Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Mon Nov 2 18:08:30 UTC 2015:. Check snapshot logs for details. (Executor::NonZeroExitStatus)
[2015-11-02T18:08:30.366Z] ERROR [4515] : Command CMD-Startup(stage 1) failed!
What's odd is that when I use elastic beanstalk CLI to deploy locally, it works fine. Any ideas on what could be happening here?
You'll want to add the following bit to your Dockerrun.aws.json file to get past this issue.
"Volumes": []

Elastic Beanstalk with Docker deployment failure

I'm trying to deploy my application with docker and elastic beanstalk. My Dockerrun.aws.json file looks like
{
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "jvans/maven_weekly",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "5000"
}],
"Volumes": [
{
"HostDirectory": "/Users/jamesvanneman/Code/maven_weekly/maven_weekly",
"ContainerDirectory": "/maven_weekly"
}
],
"Logging": "/var/log/nginx"
}
I created this application with eb create and when I run eb deploy I get
Docker container quit unexpectedly after launch: Docker container quit
unexpectedly on Mon Sep 21 01:15:12 UTC 2015:. Check snapshot logs for details.
Hook /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
In var/log/eb-activity.log I see the following errors:
Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Mon Sep 21 01:08:52 UTC 2015:. Check snapshot logs for details. (ElasticBeanstalk::ExternalInvocationError)
caused by: 83ea9b7f9a069eeb8351fef7aaedb8374f7dfe300a5e0aaeba0fe17600583175
[2015-09-21T01:08:52.205Z] INFO [2246] - [Application deployment/StartupStage1/AppDeployEnactHook/00run.sh] : Activity failed.
So it seems like there's a problem with a startup script. If i ssh into the container and try to run it manually I don't really get any extra help from error messages.
eb ssh
sudo /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh
Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Mon Sep 21 01:34:52 UTC 2015:. Check snapshot logs for details.
Msg: Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Mon Sep 21 01:34:52 UTC 2015:. Check snapshot logs for details.
Are snapshot logs something different than what's in var/log/eb-activity.log? Any Idea what is going on/how I can debug this further?
Docker dumps are stored in the host box at /var/log/eb-docker/containers/.
Go there and you'll find the docker startup crash log that should indicate the root cause of your problem.
You want to look at
/var/log/eb-docker/containers/eb-current-app/unexpected-quit.log
in the bundle downloaded by eb logs --all or using eb ssh. This log file will have the stdout and stderr of your application before it crashed.
In my case, unexpected-quit.log was empty and the other log files in /var/log/ didn't help.
So I found out why the container was crashing by manually running the image on the server.
[ec2-user#ip-xxx-xxx-xxx-xxx ~]$ nano Dockerfile # or clone the entire project
[ec2-user#ip-xxx-xxx-xxx-xxx ~]$ sudo docker build -t test .
[ec2-user#ip-xxx-xxx-xxx-xxx ~]$ sudo docker run --rm test
Exception in thread "main" …
I fixed that exception, redeployed a new version and now the container starts without issues.
In my case I did an eb ssh to connect into the ec2 instance and looked at my server logs. It was an application error. Nothing to do with AWS. Fixed it. Tried again and it's working!

Why am I getting a permission denied error on docker/aws eb?

I don't know why but I cannot seem to figure out why this is happening. I can build and run the docker image locally.
Recent Events:
2015-05-25 12:57:07 UTC+1000 ERROR Update environment operation is complete, but with errors. For more information, see troubleshooting documentation.
2015-05-25 12:57:07 UTC+1000 INFO New application version was deployed to running EC2 instances.
2015-05-25 12:57:04 UTC+1000 INFO Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2015-05-25 12:57:04 UTC+1000 ERROR [Instance: i-4775ec9b] Command failed on instance. Return code: 1 Output: (TRUNCATED)... run Docker container: vel="fatal" msg="Error response from daemon: Cannot start container 02c057b331bf3a3d912bf064f1dca3e00c95746b5748c3c4a28a5c6b452ff335: [8] System error: exec: \"bin/app\": permission denied" . Check snapshot logs for details. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/04run.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
2015-05-25 12:57:03 UTC+1000 ERROR Failed to run Docker container: vel="fatal" msg="Error response from daemon: Cannot start container 02c057b331bf3a3d912bf064f1dca3e00c95746b5748c3c4a28a5c6b452ff335: [8] System error: exec: \"bin/app\": permission denied" . Check snapshot logs for details.
Dockerfile:
FROM java:8u45-jre
MAINTAINER Terence Munro <terry#zenkey.com.au>
ADD ["opt", "/opt"]
WORKDIR /opt/docker
RUN ["chown", "-R", "daemon:daemon", "."]
USER daemon
ENTRYPOINT ["bin/app"]
EXPOSE 9000
Dockerrun.aws.json:
{
"AWSEBDockerrunVersion": "1",
"Ports": [
{
"ContainerPort": "9000"
}
],
"Volumes": []
}
Additional logs as attachment at: https://forums.aws.amazon.com/thread.jspa?threadID=181270
Any help is extremely appreciated.
#nick-humrich suggestion of trying eb local run worked. So using eb deploy ended up working.
I had previously been uploading through the web interface.
Initially using eb deploy was giving me a ERROR: TypeError :: data must be a byte string but I found this issue which was resolved by uninstalling pyopenssl.
So I don't know why the web interface was giving me permission denied perhaps something to do with the zip file?
But anyway I'm able to deploy now thank you.
I had a similar problem running Docker on Elastic Beanstalk. When I pointed CMD in the Dockerfile to a shell script (/path/to/my_script.sh), the EB deployment would fail with
/path/to/my_script.sh: Permission denied.
Apparently, even though I had run RUN chmod +x /path/to/my_script.sh during the Docker build, by the time the image was run, the permissions had been changed. Eventually, to make it work I settled on:
CMD ["/bin/bash","-c","chmod +x /path/to/my_script.sh && /path/to/my_script.sh"]

Error deploying Play Framework on AWS Beanstalk Docker

Im running a Play Framework app on AWS Beanstalk with Docker (64bit Amazon Linux 2015.03 v1.4.1 running Docker 1.6.0).
Docker File:
FROM relateiq/oracle-java8
MAINTAINER XXXX
EXPOSE 9000
ADD files /
WORKDIR /opt/docker
RUN ["chown", "-R", "daemon", "."]
RUN ["chmod", "+x", "bin/app"]
USER daemon
ENTRYPOINT ["bin/app"]
CMD []
Dockerrun.aws.json
{
"AWSEBDockerrunVersion": "1",
"Ports": [{
"ContainerPort": "9000"
}]
}
When the instance first starts I get about 1 minute where its deployed as normal, then after I browse a few pages the error shows:
502 Bad Gateway
nginx/1.6.2
The error in the ElasticBeanstalk logs is:
Play server process ID is 1 This application is already running (Or delete /opt/docker/RUNNING_PID file).
I also get in the /var/log/docker-events.logthe following messages every 30 seconds:
2015-05-30T20:07:58.000000000Z d0425e47095e5e2637263a0fe9b49ed759f130f31c041368ea48ce3d99d1e947: (from aws_beanstalk/current-app:latest) start
2015-05-30T20:08:15.000000000Z d0425e47095e5e2637263a0fe9b49ed759f130f31c041368ea48ce3d99d1e947: (from aws_beanstalk/current-app:latest) die
2015-05-30T20:08:16.000000000Z d0425e47095e5e2637263a0fe9b49ed759f130f31c041368ea48ce3d99d1e947: (from aws_beanstalk/current-app:latest) start
2015-05-30T20:08:31.000000000Z d0425e47095e5e2637263a0fe9b49ed759f130f31c041368ea48ce3d99d1e947: (from aws_beanstalk/current-app:latest) die
Can anyone see my issue? Cheers.
Adding the following to build.sbt should resolve the issue:
javaOptions in Universal ++= Seq("-Dpidfile.path=/dev/null")