Docker Community Forums

Share and learn in the Docker community.

How to run Dockerized Python app hosted on AWS ECS?

aws
amazonwebservices

(Tadbeer) #1

I have containerised a simple python scipt.

#python_script.py
print(“test message”)

#dockerfile
FROM python:2.7
ADD python_script.py /
CMD ['python", 'python_script.py"]

I have created a Docker container by this dockerfile on AWS ECS.

What is the method of running this python app? How to instruct this docker container, hosted on AWS, to run this python program?

I know how to run this container’s python app, if I had built this container on my own computer. I cant figure out how to run the container that is hosted on AWS.


(Sam) #2

you have to upload your image to the aws dockerhub

then install docker on your aws ecs instance and then run it

or,

you can upload your files thru s3 buckets and docker build on that ec2 instance and run from there


(David Maze) #3

What problems are you running into? Can you ssh to the EC2 instance and docker run the same image the same way? You’ve read the ECS documentation?


(Tadbeer) #4

David, I dont know how to SSH into my EC2 instance, to docker run the same image. Could you please tell about the same?


(David Maze) #5

Amazon Elastic Compute Cloud is a service that essentially rents virtual machines by the hour (more recently, by the second). Elastic Container Service is a basic Docker container scheduler that runs on top of EC2. Amazon Web Services publishes a lot of documentation (and IMHO it’s better organized than Docker’s); the Getting Started with Amazon EC2 Linux Instances writeup and Connecting to Your Linux Instance Using SSH have reasonably detailed instructions.

From your initial description it sounded like you had a working image already and were just trying to run it on ECS. Docker has an official tutorial that builds and runs a custom image (a Python app even!), but ignore the rest of their tutorials; “services”, “swarms”, and “stacks” are functionality that’s duplicated in ECS (and Kubernetes and other popular container schedulers).

The only other thing I’d call out that might not be clear from the basic documentation is that you must push your built image to some Docker registry to use ECS. If you’re in a mostly-Amazon environment already, their Elastic Container Registry works fine, if you don’t mind very very long image names. The normal Docker Hub will work fine too. But ECS doesn’t make it super-easy to locally build an image, and the "I don’t want to build an image for real so I’ll inject my application code using docker run -v" trick won’t work either.