制作本地镜像
以定制jdk11镜像为例:
- 新建文件夹jdk11
- 下载orcale jdk11,复制orcale jdk11 到刚刚新建文件夹jdk11下
- 新建Dockerfile,镜像对字符集和时间都做了处理
FROM centos:7
MAINTAINER cc <cc@qq.com>
ADD jdk-11.0.10_linux-x64_bin.tar.gz /usr/local/java/
ENV LANG en_US.utf8
ENV TZ Asia/Shanghai
ENV JAVA_HOME /usr/local/java/jdk-11.0.10
ENV PATH $JAVA_HOME/bin:$PATH
CMD ["java","-version"]
RUN yum -y install fontconfig && yum -y install dejavu-sans-fonts-2.33-6.el7.noarch && yum -y install dejavu-sans-mono-fonts-2.33-6.el7.noarch && yum -y install dejavu-serif-fonts-2.33-6.el7.noarch
- 创建镜像
docker build -t jdk11 .
推送至Harbor私服
- 给镜像打标签
docker tag jdk11:latest 192.168.1.106:81/test/jdk11:latest
- 登录Harbor私服
docker login 192.168.1.106:81 -u test1 -p Test123456
- 推送镜像
docker push 192.168.1.106:81/test/jdk11:latest
- 过程中常见错误解决方法
- docker配置中添加私服地址,重启docker服务
vim /etc/docker/daemon.json
{
"registry-mirrors": [ "https://registry.docker-cn.com"],
"insecure-registries": [ "192.168.1.106:81"]
}
sudo systemctl daemon-reload
sudo systemctl restart docker
推送镜像到dockerhub
-
访问https://hub.docker.com/ ,并创建仓库
-
给镜像打标签
docker tag jdk11:latest hcd1129/jdk11:latest
2. 登录dockerhub,输入账号密码
docker login
3. 推送镜像
docker push hcd1129/jdk11:latest