1.准备镜像文件tomcat 压缩包,jdk压缩包
2.如果dockerfile的名字就是Dockerfile的话,就不需要-f写名字了。
FROM centos MAINTAINER test<12345.qq.com> COPY readme.txt /usr/local/readme.txt #拷贝本地的一个文件到镜像里 ADD jdk-8u110-linux-x64.tar.gz /usr/local/ #添加一个压缩包,docker会自动解压 ADD apache-tomcat-9.0.22.tar.gz /usr/local/ RUN yum -y install vim ENV MYPATH /usr/local WORKDIR $MYPATH ENV JAVA_HOME /usr/local/jdk1.8.0_11 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.22 ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.22 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin EXPOSE 8080 #暴露端口8080 CMD /usr/local/apache-tomcat-9.0.22/bin/startup.sh && tail -F /url/local/apache-tomcat-9.0.22/bin/logs/catalina.out
2.docker build -t mytomcat .
直接build
制作好自己的镜像后
1.到docker hub上注册自己的账号
2.确定这个账号可以登录
3.docker login --help
4.登录完毕后提交镜像,docker push
[root@localhost dockerfile]# docker login -u johnmand 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
但是被拒绝了,修改一个名字和tag,push成功了。
[root@localhost dockerfile]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@localhost dockerfile]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mycentos_entry 1.0 fd27bd2e1724 52 minutes ago 231MB cmd-test latest 73e6698def47 about an hour ago 231MB mycentos 1.0 09170a90d5db about an hour ago 326MB kuangshen/centos latest 915412bdf8be 21 hours ago 231MB mysql latest 3218b38490ce 5 weeks ago 516MB hello-world latest feb5d9fea6a5 4 months ago 13.3kB centos latest 5d0da3dc9764 4 months ago 231MB [root@localhost dockerfile]# docker push mycentos:1.0 The push refers to repository [docker.io/library/mycentos] 0aa38e56c72a: Preparing c26377eceefa: Preparing 398d5576724b: Preparing 74ddd0ec08fa: Preparing denied: requested access to the resource is denied [root@localhost dockerfile]# ^C [root@localhost dockerfile]# docker ps ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@localhost dockerfile]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mycentos_entry 1.0 fd27bd2e1724 52 minutes ago 231MB cmd-test latest 73e6698def47 about an hour ago 231MB mycentos 1.0 09170a90d5db about an hour ago 326MB kuangshen/centos latest 915412bdf8be 21 hours ago 231MB mysql latest 3218b38490ce 5 weeks ago 516MB hello-world latest feb5d9fea6a5 4 months ago 13.3kB centos latest 5d0da3dc9764 4 months ago 231MB [root@localhost dockerfile]# docker push mycentos:1.0 The push refers to repository [docker.io/library/mycentos] 0aa38e56c72a: Preparing c26377eceefa: Preparing 398d5576724b: Preparing 74ddd0ec08fa: Preparing denied: requested access to the resource is denied [root@localhost dockerfile]# ^C [root@localhost dockerfile]# ^C [root@localhost dockerfile]# docker tag 09170a90d5db johnmand/mycentos:2.0 [root@localhost dockerfile]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE mycentos_entry 1.0 fd27bd2e1724 56 minutes ago 231MB cmd-test latest 73e6698def47 about an hour ago 231MB johnmand/mycentos 2.0 09170a90d5db 2 hours ago 326MB mycentos 1.0 09170a90d5db 2 hours ago 326MB kuangshen/centos latest 915412bdf8be 21 hours ago 231MB mysql latest 3218b38490ce 5 weeks ago 516MB hello-world latest feb5d9fea6a5 4 months ago 13.3kB centos latest 5d0da3dc9764 4 months ago 231MB [root@localhost dockerfile]# docker push johnmand/mycentos:2.0 The push refers to repository [docker.io/johnmand/mycentos] 0aa38e56c72a: Pushed c26377eceefa: Pushed 398d5576724b: Pushed 74ddd0ec08fa: Pushed 2.0: digest: sha256:d87b073f06360a7e7889f141413f6274bc610ffd100a0fa9cc4892c4e1df325d size: 1160



