docker:制作镜像+上传镜像+拉取镜像
1.dockerfile制作镜像
示例内容:
1.创建一个index.js的文件
console.log("hello world")
2.在相同目录下创建名为dockerfile的文件
FROM node:alpine
COPY index.js /index.js
CMD node /index.js
3.构建镜像
docker build -t minterra/hello-docker .
说明:minterra是我的docker hub用户名,hello-docker是我的镜像名称
遇到的问题:
ERROR [internal] load metadata for docker.io/library/node:alpine
我的解决方案:
(1)登录docker Desktop
(2)配置仓库镜像源
"registry-mirrors": ["https://hub.littlediary.cn","https://docker.1ms.run"]
2.上传镜像
(1)登录docker hub
docker login -u minterra -p zhaomin182
(2)上传push
说明:minterra是我的dockerhub用户名,hello-docker是镜像名称,tag是标签名,不写默认是latest
docker push minterra/hello-docker:tag
3.拉取镜像
如果想在其他网站拉取镜像:
示例:这是一个可以让我们联系使用docker的网站
https://labs.play-with-docker.com
docker pull minterra/hello-docker:tag
运行并默认创建对应容器:
docker run minterra/hello-docker:tag