Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sample_docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/*
19 changes: 19 additions & 0 deletions sample_docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# base image is python3.6 installed debian, can be changed to any other os
FROM python:3.6-stretch

# copying all the files in current path to app folder which can be found in the container also
COPY . /app
# changing dir
WORKDIR /app/

# commands that need to be run in terminal of the image that is being built
RUN apt-get update -y
RUN apt-get install python3-pip python3-dev -y
RUN apt-get install build-essential pkg-config -y

RUN python3 -m pip install requirements.txt

# exposing port so that can be accessed from out side container(from host system)
EXPOSE 1111
# command
CMD ["sh","-c","python3 app.py"]
58 changes: 58 additions & 0 deletions sample_docker/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Basic guide to have a dockerzie a flask app

Flask : https://flask-doc.readthedocs.io/en/latest/

Docker: https://docs.docker.com/

Fastapi: https://fastapi.tiangolo.com/

## CMD to build docker image :
1. Any build arguments, tags needed should be added here.
2. By default . points to Dockerfile and u can give filename by -f argument.

```$ sudo docker build -t imagename .```

## CMD to run docker image
1. Any environment variables needed to run the docker container goes here with -e argument
2. port mapping is hostport:exposeddockerport
3. -d is for detach, if you need the the logs you can do -it

```$ sudo docker run -d -p 1111:1111 --name containername imagename```

## To See current running images and containers
1. Images
```$ sudo docker images```
2. Containers
```$ sudo docker ps -a```
3. Stats of a running container
```$ sudo docker stats containername```


## CMD to ssh into a running docker container
1. Container should be running

```$ sudo docker exec -it containername /bin/bash```



## Clean up
1. To delete all unused(not attached to any container) images.

```$ sudo docker system prune -a```
2. To stop a running container.

```$ sudo docker stop containername```
3. To delete an image., -f can be used to force

```$ sudo docker rmi image name```


### Things to check :
1. If the port being used in the flask app and the port exposed in Dockerfile are same.
2. As we do in git to ignore files we add the path to `.gitignore`, same can be done with `.dockerignore`

### Other things to checkout:
1. Attaching volumes to a container
2. Adding in newrelic for logging.
3. instead of docker `run` one can try docker `compose`,`start`,`stop`

15 changes: 15 additions & 0 deletions sample_docker/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/", methods=['GET,POST'])
def index():
print(request.headers)
print(request.json)
print(request.body)

return jsonify("success"),200

if __name__=="__main__":
app.run(debug=True, host='0.0.0.0', port=1111)

1 change: 1 addition & 0 deletions sample_docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask==1.0.1