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
- Create a ubuntu virtual machine
- Enable port 8080 on the virtual machine
- Switch to the admin mode
- Create a sample flask file
- Create the other required files
- Install the docker
- Run commands to create the docker image and container
- Output
Create A Ubuntu Virtual Machine
Click to Enlarge
Enable Port 8080 On The Virtual Machine
Click to Enlarge
Switch To The Admin Mode
Create A Sample Flask File
from flask import Flask
import os
app = Flask(__name__)
@app.route('/')
def hello():
return('Hello from container..This is my first docker container\n')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)
Create The Other Required Files
FROM python:3.7
COPY . /tmp
RUN pip install flask
EXPOSE 8080
CMD ["python", "/tmp/myapp.py"]
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
Output
<ip address of virtual machine>: <port number>
Click to Enlarge