首页 技术 正文
技术 2022年11月6日
0 收藏 538 点赞 433 浏览 3526 个字

我们给予ubuntu的镜像然后拷贝python的requirement.txt文件进去,再根据这个文件安装对应的python库

<!–
@page { margin: 2cm }
p { margin-bottom: 0.25cm; direction: ltr; color: #000000; line-height: 115%; text-align: justify; orphans: 0; widows: 0 }
p.western { font-family: “Calibri”, serif; font-size: 10pt; so-language: en-US }
p.cjk { font-family: ; font-size: 10pt; so-language: zh-CN }
p.ctl { font-family: “宋体”; font-size: 11pt; so-language: ar-SA }
–>

拷贝文件到docker容器。首先查找对应的容器ID。然后执行命令

docker cp 文件源路径 文件目标路径

root@zhf-maple:/home/zhf/桌面# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

f98b8e77182b maple412/ubuntu:nb_test “/bin/bash” 22 seconds ago Up 17 seconds tender_rosalind

root@zhf-maple:/home/zhf/桌面#
docker cp /home/zhf/docker/requirement.txt
f98b8e77182b:/home/software_requirement

root@f98b8e77182b:/home/software_requirement#
ls -al

total
12

drwxr-xr-x
2 root root 4096 Sep 22 06:08 .

drwxr-xr-x
4 root root 4096 Sep 22 06:08 ..

-rw-r–r–
1 root root 2058 Sep 22 06:03 requirement.txttxt

root@f98b8e77182b:/home/software_requirement#
python3 install -r requirement.txt

保存镜像:

Docker
ps -l找到最近一次修改的容器id。

root@zhf-maple:/home/zhf/桌面#
docker ps -l

CONTAINER
ID IMAGE COMMAND CREATED
STATUS PORTS NAMES

f98b8e77182b
maple412/ubuntu:nb_test “/bin/bash” 17
minutes ago Exited (1) 10 minutes ago
tender_rosalind

然后使用docker
commit 容器ID
镜像名就可以生成镜像了

root@zhf-maple:/home/zhf/docker#
docker commit f98b8e77182b maple412/ubuntu:test

sha256:bca747cf9c55617d802d9e1633c6d70149959caef49af9a44f6d0a4b840c6c96

此时查看镜像就有了我们生成的镜像

root@zhf-maple:/home/zhf/docker#
docker images

REPOSITORY
TAG IMAGE ID CREATED
SIZE

maple412/ubuntu
test bca747cf9c55 19 seconds ago 522MB

maple412/ubuntu
nb_test 1a2a83944331 8 months ago 521MB

通过docker
login -u xx -p xx 登录docker后就可以上传就成功了

root@zhf-maple:/home/zhf/docker#
docker push maple412/ubuntu:test

The
push refers to repository [docker.io/maple412/ubuntu]

21b2d81ef223:
Pushed

df28f5ba1b2a:
Pushed

2c77720cf318:
Layer already exists

1f6b6c7dc482:
Layer already exists

c8dbbe73b68c:
Layer already exists

2fb7bfc6145d:
Layer already exists

test:
digest:
sha256:0a0ecefa6226f7cb22bf8387ec2ac766ab6c958a9b38cdeecc0063da85d2e6f8
size: 1573

docker
hub上也可以看到上传的镜像

docker: 构建自己的镜像

<!–
@page { margin: 2cm }
p { margin-bottom: 0.25cm; direction: ltr; color: #000000; line-height: 115%; text-align: justify; orphans: 0; widows: 0 }
p.western { font-family: “Calibri”, serif; font-size: 10pt; so-language: en-US }
p.cjk { font-family: ; font-size: 10pt; so-language: zh-CN }
p.ctl { font-family: “宋体”; font-size: 11pt; so-language: ar-SA }
–>

对应的Dockerfile如下:

FROM ubuntu

WORKDIR /home/software_requirement

COPY ./requirement.txt /home/software_requirement

RUN apt-get update && apt-get install python3-pip –assume-yes

RUN pip3 install -r requirement.txt

这里有2点需要注意下:

1
这里的COPY命令,源路径要写相对路径。也就是requirement.txt相对于Dockerfile的位置,否则会提示找不到源路径位置

2
在使用apt-get
install的时候会遇到如下错误,提示是否需要安装,然后自动退出

Step
5/7 : RUN apt-get install python3.6

—>
Running in c96a012485da

Reading
package lists…

Building
dependency tree…

Reading
state information…

The
following additional packages will be installed:

file
libexpat1 libmagic-mgc libmagic1 libmpdec2 libpython3.6-minimal

libpython3.6-stdlib
libreadline7 libsqlite3-0 libssl1.1 mime-support

python3.6-minimal
readline-common xz-utils

Suggested
packages:

python3.6-venv
python3.6-doc binutils binfmt-support readline-doc

The
following NEW packages will be installed:

file
libexpat1 libmagic-mgc libmagic1 libmpdec2 libpython3.6-minimal

libpython3.6-stdlib
libreadline7 libsqlite3-0 libssl1.1 mime-support

python3.6
python3.6-minimal readline-common xz-utils

0
upgraded, 15 newly installed, 0 to remove and 0 not upgraded.

Need
to get 6580 kB of archives.

After
this operation, 33.7 MB of additional disk space will be used.

Do
you want to continue? [Y/n] Abort.

The
command ‘/bin/sh -c apt-get install python3.6’ returned a non-zero
code: 1

解决办法就是在命令最后加上–assume-yes

RUN
apt-get update && apt-get install python3-pip –assume-yes

上一篇: Filebeat的使用
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289