docker: Build your own image

Then we give ubuntu mirror copy of the file into the python requirement.txt, then the corresponding installation according to the document library python

Copy the file to the docker container. First, find the container corresponding ID . Then execute the command

docker cp file path to the source file destination path

root @ zhf-maple: / home / zhf / Desktop # 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



Save image:

Docker ps -l to find the vessel last modification of the above mentioned id .

root @ zhf-maple: / home / zhf / Desktop # 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


Then docker commit containers ID mirror name can generate mirroring

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

sha256: bca747cf9c55617d802d9e1633c6d70149959caef49af9a44f6d0a4b840c6c96


At this point we will have to view mirror generated image

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上也可以看到上传的镜像

 

对应的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

 

Guess you like

Origin www.cnblogs.com/zhanghongfeng/p/11569109.html