Note: This project requires Docker and Docker Compose to be installed on your system. (For installation refer to https://docs.docker.com/compose/install/)
In this repository, we will create a docker image that includes a simple python flask web application that has the following apis/endpoints:
/creation- provides the time the image was built./dynamic- a dynamic parameters / value provided when the image is built./dockerfile- provides the dockerfile the image was created with (in the image)./- returns an index.html./put- gets a file and stores it on the image runtime./get?filename- returns a file from the local store (that was uploaded previously).
Update the dynamic paramater value that is in the .env file (if necessary)
Run the following command to build the docker images from the docker-compose.yml file
Note: Changing the container port or name will require you to make the changes in the docker-compose.yml file
docker-compose build
Run the following command to start the containers
docker-compose up
In your web browser navigate to http://localhost:3000/ to view the application.
you can access the flask app endpoints by using curl command on http://localhost:5000 for example:
curl -X GET "http://localhost:5000/creation"
Note: Each app folder has its own docker and README files with instructions to run each image separately
To view the Flask app navigate to folder flask-backend (https://github.com/deyaa562/docker-app/tree/master/flask-backend)
To view the React app navigate to folder react-frontend (https://github.com/deyaa562/docker-app/tree/master/react-frontend)
you can view the logs for a container (service) use:
docker-compose logs service-name
in our case use:
docker-compose logs backend
First we need to find out the name or ID of the container using :
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d4f4c89aaff react-frontend "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:3000->3000/tcp react-frontend-container
5e1b77a0ff6b flask-backend "python app.py" 5 minutes ago Up 5 minutes 0.0.0.0:5000->5000/tcp flask-backend-container
Then run the following:
docker logs flask-backend-container
NOTE : you can use the -f flag to both docker and docker-compose logs to view the logs in real time (
docker logs -f flask-backend)
To stop the containers (services) that were started using docker-compose use:
docker-compose stop
To stop a specific service using docker-compose use:
docker-compuse stop service-name
docker-compose down
docker-compose stop <service-name>
docker-compose rm <service-name>