我们很多时候是需要制作属于自己的镜像的,因为不是所有的镜像都是根据你的环境来制作的,所以我们要做一些自己的修改
第一步:
1 |
sudo docker pull docker.io/nginx |
先下载一个基础镜像
1 |
sudo docker run --name my-nginx -d -p 8380:80 nginx |
run这个镜像
1 |
sudo docker exec -ti my-nginx bash |
修改一些东西:
1 |
echo 'my Page' > /usr/share/nginx/html/index.html |
exit 之后
1 2 |
$curl localhost:8380 my Page |
停止镜像
1 |
docker stop my-nginx |
然后修改
1 |
docker commit -a 'zhiming' -m 'Changed index.html page' my-nginx |
然后通过
1 2 3 |
docker images <none> <none> 143773fe71cf 26 seconds ago 181.4 MB |
然后使用tag命令
1 |
sudo docker tag 143773fe71cf www.503error.com/my-nginx:1.1 |
1 2 3 |
docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE www.503error.com/my-nginx 1.1 143773fe71cf 2 minutes ago 181.4 MB |
这个时候我们就可以基于这个镜像创建我们的容器了
1 2 3 |
sudo docker run --name new-nginx -d -p 8280:80 www.503error.com/my-nginx:1.1 curl localhost:8280 my Page |
注意:这个镜像是存在我们本机的,如果本机弄丢了,就没了,所以还是push到registry中比较安全
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021