记录:在ubuntu下docker安装python并打包成dockerfile步骤
ubuntu:
一、基本操作
1、切换源:
/etc/apt/sources.list
使用echo "{index of /ubuntu/}"> sources.list在此处添加源
添加指定源
{
"registry-mirrors":
[
"docker.m.daocloud.io/"
]
}
2、更新工具包
apt-get update
二、官方安装docker步骤
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
三、使用docker拉取hub上的python3.13
docker pull python:3.13
四、使用dockerfile创建自己的python环境
#创建dockerFile,在该目录下为自己的python环境
touch dockerfile
sudo vim dockerfile
dockerfile 文本内容如下:
#使用临时源来获取python环境
FROM docker.m.daocloud.io/python:3.13
WORKDIR /app
#自补充...
#暴露端口
EXPOSE {port}
使用docker进行打包:{name}为打包名称
docker build -t {name} .
运行指定docker环境
docker run -d --name my-python-container {name}
五、出现问题
问题: Error response from daemon:Get "https://registry-1.docker.io/v2/": context deadline exceeded
在/etc/docker/创建daemon.json,修改镜像源
{
"registry-mirrors":
[
"https://docker.m.daocloud.io/",
"https://huecker.io/",
"https://dockerhub.timeweb.cloud",
"https://noohub.ru/",
"https://dockerproxy.com",
"https://docker.mirrors.ustc.edu.cn",
"https://docker.nju.edu.cn",
"https://xx4bwyg2.mirror.aliyuncs.com",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
浙公网安备 33010602011771号