Articles → DOCKER → Create Our First Docker Image And Container

Create Our First Docker Image And Container

What Is A Docker Image?

What Is A Docker Container?

Create Your First Docker Image And Container

  1. Create a ubuntu virtual machine
  2. Enable port 8080 on the virtual machine
  3. Switch to the admin mode
  4. Create a sample flask file
  5. Create the other required files
  6. Install the docker
  7. Run commands to create the docker image and container
  8. Output

Create A Ubuntu Virtual Machine

Picture showing the new ubuntu virtual machine created
Click to Enlarge

Enable Port 8080 On The Virtual Machine

Picture showing enabling the inbound port 8080  in the virtual machine
Click to Enlarge

Switch To The Admin Mode

sudo -i

Create A Sample Flask File

from flask import Flask
import os

app = Flask(__name__)

def hello():
    return('Hello from container..This is my first docker container\n')

if __name__ == '__main__':'', port=8080, debug=True)

Create The Other Required Files

FROM python:3.7
COPY . /tmp
RUN pip install flask
CMD ["python", "/tmp/"]


Install The Docker

Run Commands To Create The Docker Image And Container

docker build -t myapp-21jan:1.0 .

docker run -d --name c1 -p 8080:8080 myapp-21jan:1.0


<ip address of virtual machine>: <port number>

Picture showing the output of application in the browser
Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Tuesday, February 28, 2023


Your Email Id  
Query/FeedbackCharacters remaining 250