Tuesday, 7 June 2022

Build an Image and Push to Docker Hub


mkdir demo && cd demo


app.py  Dockerfile  requirements.txt

cat app.py

from flask import Flask

import os

import socketapp = Flask(__name__)@app.route(“/”)def hello():

html = “<h3>Hello {name}!</h3>” \

            “<b>Hostname:</b> {hostname}<br/>”

return html.format(name=os.getenv(“NAME”, “world”), hostname=socket.gethostname()) if __name__ == “__main__”:

     app.run(host=’', port=80)

cat requirements.txt


cat Dockerfile

FROM python


ADD . /app

RUN pip install -r requirements.txt


ENV NAME world

CMD [“python”, “app.py”]

sudo docker build -t python_image .

Sending build context to Docker daemon  4.096kB

Step 1/7 : FROM python

latest: Pulling from library/python

e756f3fdd6a3: Pull complete

bf168a674899: Pull complete

e604223835cc: Pull complete

6d5c91c4cd86: Pull complete

2cc8d8854262: Pull complete

2767dbfeeb87: Pull complete

e5f27d860d89: Pull complete

98a3e4f5f5ed: Pull complete

5f15c8bc4073: Pull complete

Digest: sha256:cddebe04ec7846e28870cf8624b46313a22e6407b51ced3776588784caa12d27

Status: Downloaded newer image for python:latest

 ---> e4ccc57bca82

Step 2/7 : WORKDIR /app

 ---> Running in ff2ddecedf1a

Removing intermediate container ff2ddecedf1a

 ---> 216451a196d4

Step 3/7 : ADD . /app

 ---> 8798f58d3ca4

Step 4/7 : RUN pip install -r requirements.txt

 ---> Running in 7b16d7706700

Collecting Flask

  Downloading Flask-2.1.2-py3-none-any.whl (95 kB)


 ---> 1c5329bdcfa4

Step 5/7 : EXPOSE 80

 ---> Running in f2b2069cde38

Removing intermediate container f2b2069cde38

 ---> d54fa11a3081

Step 6/7 : ENV NAME world

 ---> Running in 575ab4d7ebc4

Removing intermediate container 575ab4d7ebc4

 ---> 69aeb91ae6f1

Step 7/7 : CMD [“python”, “app.py”]

 ---> Running in bd240f809762

Removing intermediate container bd240f809762

 ---> b79fddc1c1c7

Successfully built b79fddc1c1c7

Successfully tagged python_image:latest

sudo docker images

REPOSITORY                 TAG       IMAGE ID       CREATED              SIZE

python_image               latest    b79fddc1c1c7   About a minute ago   932MB

 sudo docker login

Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.

Username: jpmolekunnel


Login Succeeded

sudo docker tag python_image jpmolekunnel/python_image:Version1

sudo docker images

REPOSITORY                  TAG        IMAGE ID       CREATED          SIZE

jpmolekunnel/python_image   Version1   b79fddc1c1c7   21 minutes ago   932MB

python_image                latest     b79fddc1c1c7   21 minutes ago   932MB

sudo docker push jpmolekunnel/python_image:Version1

The push refers to repository [docker.io/jpmolekunnel/python_image]

cf3c9222e477: Pushed

0382ebd3d0c9: Pushed

71b4186a91d4: Pushed

9fda40ddc568: Mounted from library/python

428e1f341db7: Mounted from library/python

9ea8d200cd5d: Mounted from library/python

13b045a1dfd2: Mounted from library/python

2fbabeba902e: Mounted from library/python

ee509ed6e976: Mounted from library/python

9177197c67d0: Mounted from library/python

7dbadf2b9bd8: Mounted from library/python

e7597c345c2e: Mounted from library/python

Version1: digest: sha256:eee7610b131194e4895e8ab32b5d63eb557004975e3e355f9953bd6a657a0a19 size: 2843


No comments:

Post a Comment