- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Docker Run Old Python Versions (3.10) In Container - Tutorial Linux Mint 22.3 x86_64 kernel 6.17
sudo apt update
sudo apt install docker.io -y
sudo usermod -aG docker $USER
mkdir docker-probe && cd docker-probe
server.py
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import sys
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/probe':
response = {"python_version": sys.version.split()[0], "message": "Container responding"}
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps(response).encode())
else:
self.send_response(404)
self.end_headers()
# Get the port from command line argument
port = int(sys.argv[1])
print(f"Python code listening inside container on port {port}")
HTTPServer(('0.0.0.0', port), Handler).serve_forever()
-------------------------------------------
Dockerfile
# software-properties-common provides the 'add-apt-repository' command
# This command adds external software repositories (like PPAs) to your system
# Without this package, you cannot add the deadsnakes PPA
# add-apt-repository adds the deadsnakes PPA to Ubuntu's list of package sources
# The -y flag automatically answers "yes" to the confirmation prompt
# The ppa:deadsnakes/ppa points to https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
# This PPA contains older Python versions (like 3.10) for newer Ubuntu releases
FROM ubuntu:24.04
RUN apt update && apt install -y software-properties-common
RUN add-apt-repository -y ppa:deadsnakes/ppa
RUN apt update && apt install -y python3.10
COPY server.py .
CMD ["python3.10", "server.py"]
---------------------------------------------
docker build -t probe-image .
# Pass 7000 to the Python code, map host 5000 to container 7000
docker run --rm --name my-probe -p 5000:7000 -d probe-image python3.10 server.py 7000
# --rm deletes the container after use, a container is just something you use once, and its based on the image created from above. The image is based on the Dockerfile
# Connect to host port 5000, Docker forwards to container port 7000, Python receives on 7000
# python3.10 server.py 7000 is like what you would give as a command in the bash terminal generated by the container you are spinning up.
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
curl http://localhost:5000/probe
# clean up and researching the docker command
docker stop my-probe
docker rmi probe-image
cd .. && rm -rf docker-probe
docker run --help
Видео Docker Run Old Python Versions (3.10) In Container - Tutorial Linux Mint 22.3 x86_64 kernel 6.17 канала t3kmaster
sudo apt install docker.io -y
sudo usermod -aG docker $USER
mkdir docker-probe && cd docker-probe
server.py
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
import sys
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/probe':
response = {"python_version": sys.version.split()[0], "message": "Container responding"}
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json.dumps(response).encode())
else:
self.send_response(404)
self.end_headers()
# Get the port from command line argument
port = int(sys.argv[1])
print(f"Python code listening inside container on port {port}")
HTTPServer(('0.0.0.0', port), Handler).serve_forever()
-------------------------------------------
Dockerfile
# software-properties-common provides the 'add-apt-repository' command
# This command adds external software repositories (like PPAs) to your system
# Without this package, you cannot add the deadsnakes PPA
# add-apt-repository adds the deadsnakes PPA to Ubuntu's list of package sources
# The -y flag automatically answers "yes" to the confirmation prompt
# The ppa:deadsnakes/ppa points to https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
# This PPA contains older Python versions (like 3.10) for newer Ubuntu releases
FROM ubuntu:24.04
RUN apt update && apt install -y software-properties-common
RUN add-apt-repository -y ppa:deadsnakes/ppa
RUN apt update && apt install -y python3.10
COPY server.py .
CMD ["python3.10", "server.py"]
---------------------------------------------
docker build -t probe-image .
# Pass 7000 to the Python code, map host 5000 to container 7000
docker run --rm --name my-probe -p 5000:7000 -d probe-image python3.10 server.py 7000
# --rm deletes the container after use, a container is just something you use once, and its based on the image created from above. The image is based on the Dockerfile
# Connect to host port 5000, Docker forwards to container port 7000, Python receives on 7000
# python3.10 server.py 7000 is like what you would give as a command in the bash terminal generated by the container you are spinning up.
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
curl http://localhost:5000/probe
# clean up and researching the docker command
docker stop my-probe
docker rmi probe-image
cd .. && rm -rf docker-probe
docker run --help
Видео Docker Run Old Python Versions (3.10) In Container - Tutorial Linux Mint 22.3 x86_64 kernel 6.17 канала t3kmaster
docker python container probe health check linux mint ubuntu apt install engine group usermod http server json api endpoint port mapping build image run curl cleanup devops networking tutorial beginner software properties common deadsnakes ppa detached ephemeral teardown basehttp handler localhost status
Комментарии отсутствуют
Информация о видео
22 ч. 34 мин. назад
00:01:53
Другие видео канала

