“容器初始化”的版本间的差异
跳到导航
跳到搜索
(→alpine) |
|||
(未显示同一用户的4个中间版本) | |||
第1行: | 第1行: | ||
+ | =alpine= | ||
+ | [[Docker 镜像瘦身优化]] | ||
+ | |||
+ | [https://blog.csdn.net/diyiday/article/details/91439151 alpine之创建最小docker镜像] | ||
+ | |||
+ | |||
+ | [[利用Dockerfile修改容器中的apt源(debian源)]] | ||
+ | |||
=os.init= | =os.init= | ||
<pre> | <pre> | ||
+ | # debian 11 bullseye | ||
+ | echo 'deb http://mirrors.163.com/debian/ bullseye main non-free contrib | ||
+ | deb http://mirrors.163.com/debian/ bullseye-updates main non-free contrib | ||
+ | deb http://mirrors.163.com/debian/ bullseye-backports main non-free contrib | ||
+ | deb-src http://mirrors.163.com/debian/ bullseye main non-free contrib | ||
+ | deb-src http://mirrors.163.com/debian/ bullseye-updates main non-free contrib | ||
+ | deb-src http://mirrors.163.com/debian/ bullseye-backports main non-free contrib | ||
+ | deb http://mirrors.163.com/debian-security/ bullseye/updates main non-free contrib | ||
+ | deb-src http://mirrors.163.com/debian-security/ bullseye/updates main non-free contrib' >sources.list | ||
+ | # debain 10 | ||
echo 'deb http://mirrors.163.com/debian/ buster main non-free contrib | echo 'deb http://mirrors.163.com/debian/ buster main non-free contrib | ||
deb http://mirrors.163.com/debian/ buster-updates main non-free contrib | deb http://mirrors.163.com/debian/ buster-updates main non-free contrib | ||
第27行: | 第45行: | ||
4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c^C | 4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c^C | ||
− | root@myxps:~# docker commit -m "Added curl vim.tiny" -a "linuxsa.org" 8511226ff1da | + | root@myxps:~# docker commit -m "Added curl vim.tiny" -a "linuxsa.org" 8511226ff1da evan886/debian:v1 #是不是这个添加了后面的不用添加tag呢 下次 再试一下 |
sha256:9c19bdca07aa14194e93f65264ad42f18dbabc43a8bb6bc3eadd7790a67f2296 | sha256:9c19bdca07aa14194e93f65264ad42f18dbabc43a8bb6bc3eadd7790a67f2296 | ||
root@myxps:~# | root@myxps:~# | ||
第81行: | 第99行: | ||
docker push evan886/centos-nginx:v1 | docker push evan886/centos-nginx:v1 | ||
</pre> | </pre> | ||
+ | |||
+ | |||
+ | =see also= | ||
+ | [https://www.runoob.com/docker/docker-image-usage.html Docker 镜像使用] | ||
+ | [[category:container]] |
2024年10月22日 (二) 16:47的最新版本
alpine
利用Dockerfile修改容器中的apt源(debian源)
os.init
# debian 11 bullseye echo 'deb http://mirrors.163.com/debian/ bullseye main non-free contrib deb http://mirrors.163.com/debian/ bullseye-updates main non-free contrib deb http://mirrors.163.com/debian/ bullseye-backports main non-free contrib deb-src http://mirrors.163.com/debian/ bullseye main non-free contrib deb-src http://mirrors.163.com/debian/ bullseye-updates main non-free contrib deb-src http://mirrors.163.com/debian/ bullseye-backports main non-free contrib deb http://mirrors.163.com/debian-security/ bullseye/updates main non-free contrib deb-src http://mirrors.163.com/debian-security/ bullseye/updates main non-free contrib' >sources.list # debain 10 echo 'deb http://mirrors.163.com/debian/ buster main non-free contrib deb http://mirrors.163.com/debian/ buster-updates main non-free contrib deb http://mirrors.163.com/debian/ buster-backports main non-free contrib deb-src http://mirrors.163.com/debian/ buster main non-free contrib deb-src http://mirrors.163.com/debian/ buster-updates main non-free contrib deb-src http://mirrors.163.com/debian/ buster-backports main non-free contrib deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib deb-src http://mirrors.163.com/debian-security/ buster/updates main non-free contrib' >sources.list #可以看一下别人要安装的是哪些 apt install -y vim.tiny curl cron procps #usage vim.tiny vim太重了
修改已有官方镜像
注意:记住容器的 ID,稍后还会用到 docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8511226ff1da 8e022c70c28b 使用 docker commit 命令来提交更新后的副本。 4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c^C root@myxps:~# docker commit -m "Added curl vim.tiny" -a "linuxsa.org" 8511226ff1da evan886/debian:v1 #是不是这个添加了后面的不用添加tag呢 下次 再试一下 sha256:9c19bdca07aa14194e93f65264ad42f18dbabc43a8bb6bc3eadd7790a67f2296 root@myxps:~# 其中,-m 来指定提交的说明信息,跟我们使用的版本控制工具一样;-a 可以指定更新的用户信息;之后是用来创建镜像的容器的 ID;最后指定目标镜像的仓库名和 tag 信息。创建成功后会返回这个镜像的 ID 信息。 使用 docker images 来查看新创建的镜像。 root@myxps:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 9c19bdca07aa 26 seconds ago 118MB debian buster-slim 8e022c70c28b 11 days ago 69.2MB root@myxps:~# 使用 docker images 来查看新创建的镜像。 root@myxps:~# docker run -it 9c19bdca07aa bash 打上自己的tag root@myxps:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 9c19bdca07aa 4 minutes ago 118MB debian buster-slim 8e022c70c28b 11 days ago 69.2MB root@myxps:~# docker tag 9c19bdca07aa evan886/debian:v1 root@myxps:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE evan886/debian v1 9c19bdca07aa 9 minutes ago 118MB debian buster-slim 8e022c70c28b 11 days ago 69.2MB root@myxps:~# root@myxps:~# docker login docker push evan886/debian:v1
利用 Dockerfile 来创建镜像
docker build --tag evan886/centos-nginx:v1 -f nginx/Dockerfile . docker run --name nginx -p 80:80 -v /data/apps/nginx/html/:/data/apps/nginx/html/ -d -it 9a4ccef0484d 登入容器: docker exec -it jenkins /bin/bash docker push evan886/centos-nginx:v1