新建dockerfile文件
[root@yzb-centos72-3 home]# cd /
[root@yzb-centos72-3 /]# cd /home/software/
[root@yzb-centos72-3 software]# more dockerfile/dockerfile-test
FROM centos
MAINTAINER jiangleid@yonyou.com
RUN mkdir -p /home/software
WORKDIR /home/software
RUN yum install -y unzip zip;
# '***** JDK8 ******'
ADD jdk-8u121-linux-x64.tar.gz /usr/local/
RUN chmod -R 755 /usr/local/jdk1.8.0_121
# '***** TOMCAT8 ******'
ADD apache-tomcat-8.5.15.zip /usr/local
RUN unzip /usr/local/apache-tomcat-8.5.15.zip -d /usr/local/
RUN chmod -R 755 /usr/local/apache-tomcat-8.5.15
ENV JAVA_HOME /usr/local/jdk1.8.0_121
ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.15
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
EXPOSE 8080
CMD [ "/usr/local/apache-tomcat-8.5.15/bin/catalina.sh", "run" ]
[root@yzb-centos72-3 software]#
查看已有镜像
[root@yzb-centos72-3 software]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
imgcloud v1.01 7c3919bd181a 31 minutes ago 939.3 MB
docker.io/centos latest a8493f5f50ff 5 weeks ago 192.5 MB
用dockerfile新建一个镜像
[root@yzb-centos72-3 software]# docker build -t test-test2:v1.0 -f dockerfile/dockerfile-test .
Sending build context to Docker daemon 207.8 MB
Step 1 : FROM centos
---> a8493f5f50ff
Step 2 : MAINTAINER jiangleid@yonyou.com
---> Using cache
---> 4e8e442f779b
Step 3 : RUN mkdir -p /home/software
---> Using cache
---> 3a5f6466f6aa
Step 4 : WORKDIR /home/software
---> Using cache
---> d3904c2a9f97
Step 5 : RUN yum install -y unzip zip;
---> Using cache
---> 92964dd7853c
Step 6 : ADD jdk-8u121-linux-x64.tar.gz /usr/local/
---> Using cache
---> 1b8abce23f41
Step 7 : RUN chmod -R 755 /usr/local/jdk1.8.0_121
---> Using cache
---> 92ac95f4b18c
Step 8 : ADD apache-tomcat-8.5.15.zip /usr/local
---> Using cache
---> f0ce04924228
Step 9 : RUN unzip /usr/local/apache-tomcat-8.5.15.zip -d /usr/local/
---> Using cache
---> 7528cddf08a9
Step 10 : RUN chmod -R 755 /usr/local/apache-tomcat-8.5.15
---> Using cache
---> 0aa66d59cff4
Step 11 : ENV JAVA_HOME /usr/local/jdk1.8.0_121
---> Using cache
---> ee971b230f30
Step 12 : ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.15
---> Using cache
---> 560aa3b98df6
Step 13 : ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
---> Using cache
---> 32b56ef03750
Step 14 : EXPOSE 8080
---> Using cache
---> 1abb3d0d85ca
Step 15 : CMD /usr/local/apache-tomcat-8.5.15/bin/catalina.sh run
---> Using cache
---> 7c3919bd181a
Successfully built 7c3919bd181a
查看新建的镜像
[root@yzb-centos72-3 software]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
imgcloud v1.01 7c3919bd181a 33 minutes ago 939.3 MB
test-test2 v1.0 7c3919bd181a 33 minutes ago 939.3 MB
docker.io/centos latest a8493f5f50ff 5 weeks ago 192.5 MB
[root@yzb-centos72-3 software]#
启动新建的镜像
[root@yzb-centos72-3 software]# docker run -d -p 8888:8080 test-test2:v1.0
c34abecbb5006b631d35fa8a855d4657c0ef648061bb8b1e30254c119e95052c
查看启动的端口
[root@yzb-centos72-3 software]# netstat -lnpt |grep 8888
tcp6 0 0 :::8888 :::* LISTEN 1364/docker-proxy-c
[root@yzb-centos72-3 software]# [root@yzb-centos72-3 software]# docker run -d -p 8888:8080 test-test2:v1.0
浏览器访问
url:http://172.20.4.132:8888/
登录阿里docker
[root@yzb-centos72-3 software]# docker login --username=hi31401912@aliyun.com registry.cn-beijing.aliyuncs.com
Password:
Login Succeeded
Successfully built c3be3cbcbe3c
[root@yzb-centos72-3 software]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mytest v1.1 c3be3cbcbe3c 6 seconds ago 939.3 MB
docker.io/centos latest a8493f5f50ff 5 weeks ago 192.5 MB
用docker tag 新建一个符合阿里docker规则的repository,否则不能push
因为我在阿里docker上有一个
zybros/repos1
所以,进行如下操作
[root@yzb-centos72-3 software]# docker tag c3be3cbcbe3c registry.cn-beijing.aliyuncs.com/zybros/repos1:mytest-v1.1
查看新建的reposioty tag
[root@yzb-centos72-3 software]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-beijing.aliyuncs.com/zybros/repos1 mytest-v1.1 c3be3cbcbe3c About a minute ago 939.3 MB
mytest v1.1 c3be3cbcbe3c About a minute ago 939.3 MB
docker.io/centos latest a8493f5f50ff 5 weeks ago 192.5 MB
push到阿里云docker 库
[root@yzb-centos72-3 software]# docker push registry.cn-beijing.aliyuncs.com/zybros/repos1:mytest-v1.1
The push refers to a repository [registry.cn-beijing.aliyuncs.com/zybros/repos1]
39191f28aaab: Pushed
9f1a4f8eca37: Pushed
fc7c77903552: Pushed
5378e9d41f51: Pushed
655634e8c30a: Pushed
2d190d6ad165: Pushed
4f129450ea2f: Pushed
36018b5e9787: Layer already exists
mytest-v1.1: digest: sha256:f35e9165955eddfeeb9a4618be65aee467cd919a66d8958db8e5232d28d2290d size: 2007
去阿里docker可以看到已经上传成功
在另一台机器pull此镜像,并启动
查看新机器上的images
[root@yzb-centos72-4 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
登录阿里docker
[root@yzb-centos72-4 ~]# docker login --username=hi31401912@aliyun.com registry.cn-beijing.aliyuncs.com
Password:
Login Succeeded
从阿里docker进行pull images
[root@yzb-centos72-4 ~]# docker pull registry.cn-beijing.aliyuncs.com/zybros/repos1:mytest-v1.1
Trying to pull repository registry.cn-beijing.aliyuncs.com/zybros/repos1 ...
mytest-v1.1: Pulling from registry.cn-beijing.aliyuncs.com/zybros/repos1
59e69571f6c7: Pull complete
7405e0370257: Pull complete
401405e8c511: Pull complete
876b081be973: Pull complete
ca8a181fc1a4: Pull complete
f95bdea15d3c: Pull complete
0235067826f9: Pull complete
bb599ee73043: Pull complete
Digest: sha256:f35e9165955eddfeeb9a4618be65aee467cd919a66d8958db8e5232d28d2290d
查看下载的images
[root@yzb-centos72-4 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-beijing.aliyuncs.com/zybros/repos1 mytest-v1.1 c3be3cbcbe3c 24 minutes ago 939.3 MB
启动新下载的image
[root@yzb-centos72-4 ~]# docker run -d -p 8888:8080 registry.cn-beijing.aliyuncs.com/zybros/repos1:mytest-v1.1
094cfc6016244b0d45cd1a54da7f875a84e4639ea338ca516cc97f6d412dfc68
[root@yzb-centos72-4 ~]# netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22001 0.0.0.0:* LISTEN 4016/./mongod
tcp 0 0 0.0.0.0:22002 0.0.0.0:* LISTEN 4116/./mongod
tcp 0 0 0.0.0.0:22003 0.0.0.0:* LISTEN 4212/./mongod
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 805/sshd
tcp 0 0 0.0.0.0:4567 0.0.0.0:* LISTEN 1950/mysqld
tcp 0 0 0.0.0.0:21000 0.0.0.0:* LISTEN 3916/./mongod
tcp6 0 0 :::3306 :::* LISTEN 1950/mysqld
tcp6 0 0 :::22 :::* LISTEN 805/sshd
tcp6 0 0 :::8888 :::* LISTEN 23970/docker-proxy-
浏览器访问:http://172.20.4.133:8888/
The end !