这是我参与11月更文挑战的第24天,活动详情查看:2021最后一次更文挑战
深入理解Docker
1, 发布自己的镜像
DockerHub注册账号
1, 官方地址:hub.docker.com/ 注册账号
2,在我们服务器上提交我们的镜像
# 登陆
[root@VM-0-7-centos tomcat]# docker login --help
Usage: docker login [OPTIONS] [SERVER]
Log in to a Docker registry.
If no server is specified, the default is defined by the daemon.
Options:
-p, --password string Password
--password-stdin Take the password from stdin
-u, --username string Username
3, 输入: docker login -u 账号ID
[root@VM-0-7-centos tomcat]# docker login -u zlm@511
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@VM-0-7-centos tomcat]#
4, 给镜像打标签: tag
docker tag 13fa3ef9c486 zlm/diytomcat:1.0
5, 通过tag发布自己的镜像
docker push zlm/diytomcat
2, 总结
3, 前端自动化部署
1, 构建自己的Dockerfile文件
FROM centos
RUN yum -y install nodejs
RUN yum -y install nginx
WORKDIR /app
ADD . .
RUN npm install yarn -g
RUN yarn install
RUN npm run build
RUN rm -f /usr/share/nginx/html/*
VOLUME /usr/share/nginx/html
EXPOSE 80
CMD cp -r /app/build/* /usr/share/nginx/html && nginx && /bin/bash
2, 构建自己的镜像
docker build -t my-web:1.0
3, 运行自己的镜像
docker run -p 81:80 -v /User/zlm/Desktop/html:/usr/share/nginx/html -it --name="my-nginx01" my-web:1.0
4,Docker制作node镜像
- 基础镜像信息
- 维护者信息
- 镜像操作指令
- 容器启动时执行指令
当node.js遇见docker的时候:
Dockerfile应用
FROM node:12
LABEL maintainer=zlm@qq.com
# 创建app目录
WORKDIR /app
# 把package.json, package-lock.json 或者 yarn.lock复制到工作目录
COPY ["package.json", "*.lock", "./"]
# 打包app源码
# 特别注意: 要指定工作目录中的中文名字
COPY src ./src
# .dockerignore文件, 上面两个COPY 合并成一个
# 等同于: COPY . .
# 使用Yarn安装app依赖
RUN yarn --prod --registry=https://registry.npm.taobao.org
# 对对暴露端口号
EXPOSE 9527
CMD ["node", "src/index.js"]
使用: docker build打包:
docker build -t ${your_name}/${image_name}:${tag} .
比如: docker build -t zlm/node-demo: 1.0 .
其中:
.dockerignore文件:是忽略不需要打包上传的文件