I have created an application in Elastic Beanstalk to host a play framework 2 app there using instructions from this project.
I have packaged the project exactly like Docker needs but when I upload the final zip to the application I receive a permission denied error in this flow:
Environment update is starting.
Deploying new version to instance(s).
Successfully pulled dockerfile/java:latest
Successfully built aws_beanstalk/staging-app
Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Fri Sep 12 23:32:44 UTC 2014: 2014/09/12 23:32:39 exec: "bin/my-sample-project": permission denied. Check snapshot logs for details.
I have spent hours on this without any success.
This is the content of my root Dockerfile:
FROM dockerfile/java
MAINTAINER Cristi Boariu <myemail>
EXPOSE 9000
ADD files /
WORKDIR /opt/docker
RUN ["chown", "-R", "daemon", "."]
USER daemon
ENTRYPOINT ["bin/mytweetalerts"]
CMD []
Any hint how to solve this issue?
Here's what I did to solve this same issue, though I'm not sure which part specifically solved it.
My DockerFile looks like:
FROM dockerfile/java
MAINTAINER yourNameHere
EXPOSE 9000 9443
ADD files /
WORKDIR /opt/docker
RUN ["chown", "-R", "daemon", "."]
# Make sure myApp is excutable
RUN ["chmod", "+x", "bin/myApp"]
USER daemon
# If running a t1.micro or other memory limited instance
# be sure to limit play memory. This assumes play 2.3.x
ENTRYPOINT ["bin/myApp", "-mem", "512", "-J-server"]
CMD []
See https://www.playframework.com/documentation/2.3.x/ProductionConfiguration for info on setting jvm memory.
My Dockerrun.aws.json (also required) looks like:
{
"AWSEBDockerrunVersion": "1",
"Ports": [
{
"ContainerPort": "9000"
}
]
}
Finally my play application lives in files/opt/docker with the run script in docker/bin. All this is zipped up and sent to EB.
Add a chmod command to make your file executable:
RUN ["chmod", "+x", "bin/myApp"]
So your Dockerfile will be:
FROM dockerfile/java
MAINTAINER Cristi Boariu <myemail>
EXPOSE 9000
ADD files /
WORKDIR /opt/docker
RUN ["chown", "-R", "daemon", "."]
USER daemon
RUN ["chmod", "+x", "bin/myApp"]
ENTRYPOINT ["bin/mytweetalerts"]
CMD []
Related
I've got a very straightforward Flask application running in a single docker container. When I run the app using eb local run it "works" in that the docker image is built, and I eventually see the log output from flask letting me know it's ready for requests. But when I actually attempt to query the running application, the requests fail immediately with errors saying 'the site cant be reached'. It seems like the app is running in the container, but somehow the ports aren't exposed correctly? Also, when I run it using docker run ... it works completely and I'm able to query the application.
Command I'm using:
eb local run --port 5000 --envvars APP_ENV=LOCAL
My Dockerrun.aws.json:
{
"AWSEBDockerrunVersion": "1",
"Ports": [
{
"ContainerPort": 5000,
"HostPort": 5000
}
]
}
My Dockerfile:
FROM python:3
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
ENTRYPOINT [ "python" ]
CMD [ "application.py" ]
My .elasticbeanstalk/config.yml:
branch-defaults:
python3:
environment: fs-service-prod
environment-defaults:
fs-service-prod:
branch: null
repository: null
global:
application_name: followspot-service
default_ec2_keyname: null
default_platform: arn:aws:elasticbeanstalk:us-east-1::platform/Docker running on
64bit Amazon Linux/2.12.11
default_region: us-east-1
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: null
sc: git
workspace_type: Application
Output of eb local status:
Platform: 64bit Amazon Linux 2018.03 v2.12.11 running Docker 18.06.1-ce
Container name: 6739a687fa2d18f1c683926f024c88bed9f5c6c7
Container ip: 127.0.0.1
Container running: True
Exposed host port(s): 5000
Full local URL(s): 127.0.0.1:5000
Thanks so much for any help you can give me and let me know if there's a good way to go about getting more helpful info.
Figured it out! Turns out this was an issue with how I was starting my Flask app. Because flask by default runs on 127.0.0.1 and Docker by default runs tries to connect to 0.0.0.0, I needed to change how the app is started in my Dockerfile.
Instead of:
ENTRYPOINT [ "python" ]
CMD [ "application.py" ]
I had to change it to:
ENV FLASK_APP application.py
ENTRYPOINT ["python", "-m", "flask", "run", "--host=0.0.0.0"]
Then everything worked as expected.
Currently i am working on django app and trying to work with reddis server. i have add all configuration settings for reddis server in settings.py my settings are like this.
redis_host = os.environ.get('REDIS_HOST', 'my-ip-of-reddis-server')
# Channel layer definitions
# http://channels.readthedocs.org/en/latest/deploying.html#setting-up-a-channel-backend
CHANNEL_LAYERS = {
"default": {
# This example app uses the Redis channel layer implementation asgi_redis
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [(redis_host, 6380)],
},
"ROUTING": "multichat.routing.channel_routing",
},
}
its working fine when i run
python manage.py runser or python manage.py runworkers
but when i dockerize this django app, it does not make connection with reddis server. it gives following error.
redis.exceptions.ConnectionError: Error -2 connecting to redis:6380. Name or service not known.
2018-01-30 06:00:47,704 - ERROR - server - Error trying to receive messages: Error -2 connecting to redis:6380. Name or service not known.
201
My dockerfile is this.
# FROM directive instructing base image to build upon
FROM python:3-onbuild
RUN apt-get update
ENV PYTHONUNBUFFERED 1
ENV REDIS_HOST "redis"
# COPY startup script into known file location in container
COPY start.sh /start.sh
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
#RUN python manage.py runserver
RUN daphne -b 0.0.0.0 -p 8000 --ws-protocol "graphql-ws" --proxy-headers multichat.asgi:channel_layer
# CMD specifcies the command to execute to start the server running.
CMD ["/start.sh"]
# done!
and i have also tried this.
# FROM directive instructing base image to build upon
FROM python:3-onbuild
RUN apt-get update
ENV PYTHONUNBUFFERED 1
ENV REDIS_HOST "redis"
# COPY startup script into known file location in container
COPY start.sh /start.sh
# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000
RUN python manage.py runserver
RUN daphne -b 0.0.0.0 -p 8000 --ws-protocol "graphql-ws" --proxy-headers multichat.asgi:channel_layer
# CMD specifcies the command to execute to start the server running.
CMD ["/start.sh"]
# done!
But this is not making connection while containerizing my django app.
Can anybody please tell me, where i am wrong? how can i dockerize my django app that will make connection with redis server whose settings are places in settings.py.
Any help or suggestion will be highly appreciated.
Thanks.
Here is my problem:
I have a task running a Docker image on Amazon ECS but I would like to make a new Docker image from the running instance of the container.
I see the id of the instance on Amazon ECS; I have made an AMI but I would like to make a new docker image that I can pull from Amazon.
Any ideas?
Regards and thanks.
To create a image from container execute the command below:
docker commit container_id imagename
You can run docker commit (docs) to save the container to an image, then push that image with a new tag to the registry.
This can be easily done by using "docker commit".
Let's say you need an image, based on the latest from NGINX, with PHP, build-essential, and nano installed. I'll walk you through the process of pulling the image, running the container, accessing the container, adding the software, and committing the changes to a new image that can then be easily used as a base for your dev containers.
Pulling the image and running the container:
sudo docker pull nginx
sudo docker run -it --name nginx-template-base -p 8080:80 nginx
Modifying the container:
apt-get install nano
apt-get install php5
Commit the changes:
sudo docker commit CONTAINER_ID nginx-template
The newly created template is ready and you can run using:
sudo docker run -it --name nginx-dev -p 8080:80 nginx-template
Apart from the answer provided by #Ben Whaley, I personally suggest you to make use of Docker APIs. To use Docker APIs you need to configure the docker daemon port and the procedure is explained here configuring docker daemon port
Lets run a container using an base Ubuntu Image and create a folder inside the container:
#docker run -it ubuntu:14.04 /bin/bash
root#58246867493d:/#
root#58246867493d:/# cd /root
root#58246867493d:~# ls
root#58246867493d:~# mkdir TEST_DIR
root#58246867493d:~# exit
Status of the exited container:
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58246867493d ubuntu:14.04 "/bin/bash" 2 minutes ago Exited (127) 57 seconds ago hungry_turing
JSON file which is an input for committing a container:
#cat container_create.json
{
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"property1": {},
"property2": {}
},
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Cmd": null,
"Image": "ubuntu:14.04",
"Volumes": {
"additionalProperties": {}
},
"Labels": {
"property1": "string",
"property2": "string"
}
}
API to commit a container
# curl -X POST http://127.0.0.1:6000/commit?container=58246867493d\&repo=ubuntu\&tag=15.0 -d #container_create.json --header "Content-Type: application/json" | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 593 100 81 100 512 175 1106 --:--:-- --:--:-- --:--:-- 1108
{
"Id": "sha256:acac1f3733b2240b01e335642d2867585e5933b18de2264315f9b07814de113a"
}
The Id that is generated is the new Image Id which is build from committing a container.
Get docker Images
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
**ubuntu 15.0 acac1f3733b2 10 seconds ago 188MB**
ubuntu 14.04 132b7427a3b4 10 hours ago 188MB
Run the newly build Image to see the changes commited in the previous container.
# docker run -it ubuntu:15.0 /bin/bash
root#3a48af5eaec9:/# cd /root/
root#3a48af5eaec9:~# ls
TEST_DIR
root#3a48af5eaec9:~# exit
To build an image from Docker file, how to build an image using docker API
For more information on docker APIs, refer here.
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
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")