Run python file via Docker-Compose

Pardhu Guttikonda
2 min readJan 12, 2021
Photo by Shahadat Rahman on Unsplash

Prerequisites:

Docker:

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

Step-1:

create a python file. I’m using hello.py

Step-2:

Dockerfile here we are going specify

  • FROM python version: Accordingly, docker is going to pull the python image to your local machine.
  • WORKDIR: Here you are going to specify the working directory. (Place where hello.py will be there).

NOTE: The above path respective to your container not to your local machine.

  • COPY ./hello.py /usr/src/app : Copying hello.py to our container.

Step-3:

docker-compose.yml here we are going say docker to run our commands

Note: On changing the code in your python file(hello.py).To reflect the changes you have to build the docker-compose(docker-compose build).

--

--