Sample Containerizing Application Using Docker
The following steps guides in containerizing the application using Docker:
Step 1: Create Dokcerfile and Python Application
- Create a folder with 2 files (Dockerfile and main.py file) in it
Step 2: Develop Python Code
- Edit main.py with the below code, or else you can try on developing your own python code.
#!/usr/bin/env python3
print("Docker and GFG rock!")
Step 3: Develop a Dockerfile
- Edit Dockerfile with the below instructions for developing the Dockerfile:
FROM python:latest
COPY main.py /
CMD [ "python", "./main.py" ]
Step 4: Create a Docker Image
- Once you have created and edited the main.py file and the Dockerfile, create your image contain your application by running the following command:
$ sudo docker build -t python-test .
- The ‘-t’ option allows to define the name of your image. ‘python-test’ is the name we have chosen for the image.
Step 5: Run Docker Container
- Once the image is created, your code is ready to launch.
$ sudo docker run python-test
To know more about this containerization of your application, refer this – Article
What is Docker?
Docker is a set of Platforms as a service (PaaS) products that use Operating system-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating system kernel and therefore use fewer resources than a virtual machine.
Table of Content
- What is Docker?
- Why Docker is popular?
- What is a Dockerfile?
- What is Docker Architecture and How Docker Works?
- What is Docker Image?
- What is Docker Container?
- What is Docker Hub?
- What is Docker Compose?
- How to Download Docker Desktop?
- Docker Commands
- Docker Engine
- Why to use Docker?
- What is Docker For AWS?
- Difference Between Docker Containers and Virtual Machines
- Install Docker On Ubuntu
- Sample Example: Containerizing Application Using Docker
- Sample Example to Push an image to Docker Hub
- Fetch and run the image from Docker Hub
- Benefits of Docker
- Alternatives of Docker
- Docker Security