Docker Community Forums

Share and learn in the Docker community.

How to access dockerized app with a website

aws
amazonwebservices

(Tadbeer) #1

Hi. I have created a sample python addition application, which takes 2 numbers as argument and prints their sum, and dokerized this application, on an ubuntu base. I have deployed this Docker container on AWS ECS. I have also developed a sample website which asks the user to enter two numbers.
Now, How do I access my dockerised python app on AWS to perform this task for the website.

This calculator task is used as an example task for my actual python appplication that I want to access from a website.


(Rahulishu1993) #2

hi @tadbeer, python apps do not work directly on the browser. You need to configure web server to read and understand the code written in python and to make them run on the browser.
I don’t know whether you have exposed your app to the internet or not. If not exposed to internet you can run the app locally on the host running that container to check whether app is working or not.


(Tadbeer) #3

thanks Rahul.
As you said, the configured web server will read and run it on the browser. But since the website is designed in PHP, how to do this configuration, such that the website passes the given inputs to the python app deployed on the Docker.

Feel free to provide with any links that you find worthy…


(Sam) #4

just for thinking about this… how would you do the setup with a real server, webserver and php.

NOTHING is different using docker, except the commands used to do the setup

create a server (start with ubuntu)
add the apache server
add the php server plugin
do the website config (change apache.conf etc)
set the website path
set the listening ports for the https server (port=80 or 8080 or somesuch)
start the apache server

that would be your dockerfile

here is a Dockerfile for one of my php based web apps
this runs on Amazon aws, and uses an EFS shared volume as the web site source path, so the php code is not IN the container.

from ubuntu:latest
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
run apt-get -y upgrade
run apt-get update
run apt-get purge php*
RUN apt-get -y install \
    apache2 php7.0-mysql php7.0-json php7.0-cgi  php7.0 libapache2-mod-php7.0 php7.0-xml php7.0-curl php7.0-zip curl php-gd php7.0-mbstring libapache2-mod-php nfs-common iputils-ping dnsutils

# Enable apache mods.
RUN a2enmod php7.0
RUN a2enmod rewrite
run a2dismod mpm_event
run a2enmod mpm_prefork

# Manually set up the apache environment variables
ENV APACHE_RUN_USER root
ENV APACHE_RUN_GROUP root
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV WEBROOT_PATH /store-code
volume $WEBROOT_PATH

# Expose apache.
EXPOSE 80

# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
ADD apache.conf /etc/apache2/apache2.conf

# By default start up apache in the foreground, override with /bin/bash for interative.
CMD /usr/sbin/apache2ctl -D FOREGROUND

then to make this work (on a local docker host machine)

docker run -d -v source_path:/var/www/html -p0:80 container_tag

the -p0:80 means map the container port 80 to the next available free port on host.
docker inspect will show that mapping…

then http://host_ip:host_port/??? will run the php app just like always

here is my aws ECS cluster design

the web server box is the ECS instance (ec2), and it is a docker host. (cpu and memory), aws auto scaling group
the docker image IS the web server code(apache). (app code and data access) aws cluster service, task definition
so this has dual scalability

  1. ecs instance(ec2) size
  2. task (docker container) size

the aws ELB does all the wiring of the external port to the exposed docker instance port
there is only one port (80) into the VPC, and it is to the load balancer

the PHP code is on the EFS code volume, mapped to the volume $WEBROOT_PATH in the container
EFS volumes are terribly slow, so a CDN is used to cache the content outside the ECS cluster to improve speed.