Yesterday I tried to make my first docker image for my recent project, nucleotide seq generator. As I just learned what docker is and how it is useful to get out of the dependency loop, I wanted to try my hand at this. I tried to learn docker before in my life too, but I never went successful.
But yesterday, I was suggesting docker to my cousin for his new project and stumbled upon the freecodecamp docker tutorial. It is a free tutorial without ads, so I always prefer this. This particular lecture was taught by katacoda creator, a platform where you can learn a lot of DevOps-related things. What better way to learn, so I started lectures and came up with docker images, from where I left off because I wanted to deploy my own app.
I searched on YouTube and figured the way to deploy flask apps in docker by building dockerfile
. So now my journey for dockerfile
began.
Dockerfile
Is a way to create docker images for your software. In your dockerfile
give instructions to execute when that particular docker image will run.
So I created the Dockerfile
in my project repo.
After then, it's time to edit the dockerfile, after my first addition, the content inside dockerfile was like this…
from alpine:latest
RUN apk add --no-cache python3-dev \
&& pip3 --update pip3
WORKDIR /app
COPY . /app
RUN pip3 --no-cache-dir install -r requirements.txt
EXPOSE 5000
ENTRYPOINT ["python3"]
CMD ["hello.py"]
Now I tried to build the docker image but this gave me an error
ERROR: unsatisfiable constraints:
pip3 (missing):
So I had to search through a lot of questions on Stack overflow and finally found a solution by changing code to…
from alpine:latest
RUN apk add --no-cache python3-dev
RUN apk add --update py-pip
WORKDIR /app
COPY . /app
RUN pip3 --no-cache-dir install -r requirements.txt
EXPOSE 5000ENTRYPOINT ["python3"]
CMD ["hello.py"]
That was the story, I did learn something I didn’t know and had a problem trying it, overcame it, and finally completed it. If I can do that, you can too. Good Luck.