Dockerize a Python Code

Published: 20 April 2024
on channel: Atul Kamble | LearnWithAtul
76
1

Prerequisites:
//Install Docker Desktop
Docker Desktop https://www.docker.com/products/docke...

// Sign up for Docker Hub
https://hub.docker.com/

// on linux
sudo yum install docker
sudo docker login

// username and password of dockerhub account needed for practice.

// Create project folder

cd D:/project
mkdir pythondocker
cd .\pythondocker2\

// create a program code
New-Item test.py
OR
touch test.py

// Copy following code to python file
```
print("Hello, World")
```

// Edit
code test.py
OR
notepad test.py
OR
nano test.py

// Run Locally
python test.py

// Create a Dockerfile
New-Item Dockerfile
OR
touch Dockerfile

// Edit Dockerfile
code Dockerfile

// paste following code to Dockerfile
```
FROM python:latest
WORKDIR /usr/app/src
COPY test.py ./
CMD [ "python", "./test.py"]
```

// list docker images
docker images

// build docker image from Dockerfile
docker build -t atuljkamble/pythonhelloworld .

// list images
docker images

// push docker image to Dockerhub
docker push atuljkamble/pythonhelloworld

// Pull Docker image and run locally
docker pull atuljkamble/pythonhelloworld
docker run atuljkamble/pythonhelloworld


On this page of the site you can watch the video online Dockerize a Python Code with a duration of hours minute second in good quality, which was uploaded by the user Atul Kamble | LearnWithAtul 20 April 2024, share the link with friends and acquaintances, this video has already been watched 76 times on youtube and it was liked by 1 viewers. Enjoy your viewing!