Créer une image - Exemple 1

Un script app.py :

app.py
from flask import Flask
from redis import Redis, RedisError
 
... etc ...

Un fichier requirements.txt

requirements.txt
Flask
Redis

Un fichier Dockerfile :

FROM python:2.7-slim
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
EXPOSE 8000
ENV NOM Brigitte
CMD ["python", "app.py"]

Construire l'image :

docker build -t monimage .

Si l'image existe déjà, elle est renommée en <none> et la nouvelle image prend sa place.

Voir les images créées :

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
monimage            latest              56f50c6a1076        About a minute ago   159MB
python              2.7-slim            eeb27ee6b893        6 months ago         148MB

Lancer ce conteneur :

docker run -p 8000:8000 monimage