接
上。。。。
1,推送本地镜像到docker hub仓库
先下个镜像,如ubuntu
senrsl@senrsl-ubuntu:~$ docker search ubuntu
senrsl@senrsl-ubuntu:~$ docker pull ubuntu
senrsl@senrsl-ubuntu:~$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: dcjz
Password:
WARNING! Your password will be stored unencrypted in /home/senrsl/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
senrsl@senrsl-ubuntu:~$senrsl@senrsl-ubuntu:~$ docker tag ubuntu:latest dcjz/ubuntu:2021
senrsl@senrsl-ubuntu:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dcjz/ubuntu 2021 f643c72bc252 4 months ago 72.9MB
ubuntu latest f643c72bc252 4 months ago 72.9MB
senrsl@senrsl-ubuntu:~$ docker push dcjz/ubuntu:2021
The push refers to repository [docker.io/dcjz/ubuntu]
f6253634dc78: Mounted from library/ubuntu
9069f84dbbe9: Mounted from library/ubuntu
bacd3af13903: Mounted from library/ubuntu
2021: digest: sha256:4e4bc990609ed865e07afc8427c30ffdddca5153fd4e82c20d8f0783a291e241 size: 943
senrsl@senrsl-ubuntu:~$
2,简单部署一个tomcat clock镜像
复制本地资源到宿主机
SENRSL:temp senrsl$ scp -r ~/j2ee/apache-tomcat-9.0.10/webapps/clock/ senrsl@192.168.7.89:/home/senrsl/Downloads/clock/
senrsl@192.168.7.89's password:
.DS_Store 100% 6148 2.4MB/s 00:00
index.js 100% 2557 1.8MB/s 00:00
package.json 100% 90 68.3KB/s 00:00
web.xml 100% 1317 981.8KB/s 00:00
style.css 100% 1828 1.3MB/s 00:00
clock.html 100% 1514 1.2MB/s 00:00
SENRSL:temp senrsl$
这个地方搞错了,目录会重复,所以下面docker run才会少一级目录
此处应该是
SENRSL:temp senrsl$ scp -r ~/j2ee/apache-tomcat-9.0.10/webapps/clock senrsl@192.168.7.89:/home/senrsl/Downloads/clock
然后 安 Tomcat
senrsl@senrsl-ubuntu:~$ docker search tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementati… 2990 [OK]
senrsl@senrsl-ubuntu:~$ docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
b9a857cbf04d: Pull complete
d557ee20540b: Pull complete
3b9ca4f00c2e: Pull complete
667fd949ed93: Pull complete
661d3b55f657: Pull complete
511ef4338a0b: Pull complete
a56db448fefe: Pull complete
00612a99c7dc: Pull complete
326f9601c512: Pull complete
c547db74f1e1: Pull complete
Digest: sha256:94cc18203335e400dbafcd0633f33c53663b1c1012a13bcad58cced9cd9d1305
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
senrsl@senrsl-ubuntu:~$
senrsl@senrsl-ubuntu:~$ docker run -d --name tomcat-clock -p 8080:8080 -v /home/senrsl/Downloads/clock:/usr/local/tomcat/webapps/ tomcat
27cce9fef3ab940189464422538992866fd9a441257ddff7d893dca0a94d7b6b
senrsl@senrsl-ubuntu:~$
访问 http://192.168.7.89:8080/clock/clock.html 就看到了钟表
-v 参数把宿主中的目录挂载到容器
senrsl@senrsl-ubuntu:~$ docker exec -it 27cce9fef3ab /bin/bash
root@27cce9fef3ab:/usr/local/tomcat# ls webapps/clock/
.DS_Store WEB-INF/ clock.html index.js package.json style.css
root@27cce9fef3ab:/usr/local/tomcat# ls webapps/clock
WEB-INF clock.html index.js package.json style.css
root@27cce9fef3ab:/usr/local/tomcat#
然后保存
senrsl@senrsl-ubuntu:~$ docker commit 27cce9fef3ab dcjz/tomcat-clock
sha256:025a6521b5b80f077452d77c86545413cfd4cacb6608390c207c057a3aa959ab
senrsl@senrsl-ubuntu:~$ docker push dcjz/tomcat-clock
Using default tag: latest
The push refers to repository [docker.io/dcjz/tomcat-clock]
967ebb7ad53f: Pushed
9ddc8cd8299b: Mounted from library/tomcat
c9132b9a3fc8: Mounted from library/tomcat
8e2e6f2527c7: Mounted from library/tomcat
500f722b156b: Mounted from library/tomcat
7a9b35031285: Mounted from library/tomcat
7496c5e8691b: Mounted from library/tomcat
aa7af8a465c6: Mounted from library/tomcat
ef9a7b8862f4: Mounted from library/tomcat
a1f2f42922b1: Mounted from library/tomcat
4762552ad7d8: Mounted from library/tomcat
latest: digest: sha256:96ae0765f4777c32ac70bd5ab5a333ebb22afb9fe3459277e45eda8a54f933ca size: 2629
senrsl@senrsl-ubuntu:~$
然后把本地的tomcat-clock容器和镜像都删掉
重新从云端拉取
senrsl@senrsl-ubuntu:~$ docker pull dcjz/tomcat-clock
Using default tag: latest
senrsl@senrsl-ubuntu:~$ docker run -d -p 8080:8080 dcjz/tomcat-clock
a2ee28e33ceaafee7482b28cfeadc3597fcab58f67b5d3251cc68bdaa7d501b3
senrsl@senrsl-ubuntu:~$
clock目录竟然没了。。。。
重新建。。。。
senrsl@senrsl-ubuntu:~$ docker pull tomcat
senrsl@senrsl-ubuntu:~$ docker run -d --name tomcat-clock -p 8080:8080 tomcat
f110a2c3194ec7d47cae31aec6b0b2aecc99bbcf02b557dd806838bf133c655c
senrsl@senrsl-ubuntu:~$
不再挂载clock目录,直接把clock从宿主机到容器
senrsl@senrsl-ubuntu:~$ scp /home/senrsl/Downloads/clock root@172.17.0.4:/usr/local/tomcat/webapps/clock
ssh: connect to host 172.17.0.4 port 22: Connection refused
lost connection
senrsl@senrsl-ubuntu:~$ telnet 172.17.0.4 22
Trying 172.17.0.4...
telnet: Unable to connect to remote host: Connection refused
senrsl@senrsl-ubuntu:~$ docker cp -r Downloads/clock f110a2c3194ec7d47cae31aec6b0b2aecc99bbcf02b557dd806838bf133c655c:/usr/local/tomcat/webapps/clock
unknown shorthand flag: 'r' in -r
See 'docker cp --help'.
senrsl@senrsl-ubuntu:~$ docker cp Downloads/clock f110a2c3194ec7d47cae31aec6b0b2aecc99bbcf02b557dd806838bf133c655c:/usr/local/tomcat/webapps/clock
senrsl@senrsl-ubuntu:~$
容器里直接就有了
root@f110a2c3194e:/usr/local/tomcat# ls webapps
clock
root@f110a2c3194e:/usr/local/tomcat# ls webapps/clock/
WEB-INF clock.html index.js package.json style.css
root@f110a2c3194e:/usr/local/tomcat#
这时候再保存一份试试
senrsl@senrsl-ubuntu:~$ docker commit f110a2c3194e dcjz/tomcat-clock
senrsl@senrsl-ubuntu:~$ docker run -d --name tomcat-clockx2 -p 9090:8080 dcjz/tomcat-clock
712bf2196d18b019bf5d35f530da3804d8a1d2a790aa7d20de9fea191be0b0e6
senrsl@senrsl-ubuntu:~$
此时,访问9090端口访问clock也是可以的,说明需要的东西包在里面了 http://192.168.7.89:9090/clock/clock.html
senrsl@senrsl-ubuntu:~$ docker push dcjz/tomcat-clock
推送上去,再次下载验证。。。。
3,更新Tomcat镜像
之前那个镜像终于算是能使了,但是如果运行中,想要给它加个功能咋整。。。。
root@9c8b237d329c:/usr/local/tomcat/webapps# echo "this is root index">>ROOT/index.html
root@9c8b237d329c:/usr/local/tomcat/webapps#
然后直接刷新 http://192.168.7.89:9090/ 就出了这行字。。。。
然后给它保存成新tag
senrsl@senrsl-ubuntu:~$ docker commit -m="add root text" -a="senRsl" 9c8b237d329c dcjz/tomcat-clock:2021
sha256:95098e3e080e4390f4585b0db62c5bf8f90f0ab9572cc5fdbc83197e8a6f3405
senrsl@senrsl-ubuntu:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dcjz/tomcat-clock 2021 95098e3e080e 3 seconds ago 649MB
dcjz/tomcat-clock latest 813e2d99ccce 52 minutes ago 649MB
dcjz/centos7-ssh4 latest 4fbed876e3d7 20 hours ago 318MB
tomcat latest 040bdb29ab37 2 months ago 649MB
centos 7 8652b9f0cb4c 4 months ago 204MB
senrsl@senrsl-ubuntu:~$ docker run -d --name tomcat-clock-3 -p 10100:8080 dcjz/tomcat-clock:2021
b8a8fa9dd2a044457f188c6a0009e8a42682f5d20f18cae076ba691951301534
senrsl@senrsl-ubuntu:~$ docker push dcjz/tomcat-clock:2021
The push refers to repository [docker.io/dcjz/tomcat-clock]
2792538345bb: Pushed
a57401213784: Layer already exists
9ddc8cd8299b: Layer already exists
c9132b9a3fc8: Layer already exists
8e2e6f2527c7: Layer already exists
500f722b156b: Layer already exists
7a9b35031285: Layer already exists
7496c5e8691b: Layer already exists
aa7af8a465c6: Layer already exists
ef9a7b8862f4: Layer already exists
a1f2f42922b1: Layer already exists
4762552ad7d8: Layer already exists
2021: digest: sha256:e54906aa86b718657fdc21dcf40fd231c9de8d16573f387e99779e0237d80aab size: 2837
senrsl@senrsl-ubuntu:~$
运行这个镜像后,访问http://192.168.7.89:10100/clock/clock.html 和 http://192.168.7.89:10100/ 就显示了这两次修改的内容。。。。
镜像怎么这么大。。。。
4,简单使用dockerfile
研究了下tomcat,实际存储的是个docker file 文件 https://github.com/docker-library/tomcat/blob/dbe928e1d83e6ddef0d9a62a248acc3975fbda73/10.0/jdk16/openjdk-buster/Dockerfile
建个简单的Nginx镜像
senrsl@senrsl-ubuntu:~/Downloads$ ls
clock
senrsl@senrsl-ubuntu:~/Downloads$ mkdir nginx
senrsl@senrsl-ubuntu:~/Downloads$ touch nginx/Dockerfile
senrsl@senrsl-ubuntu:~/Downloads$ vi nginx/Dockerfile
senrsl@senrsl-ubuntu:~/Downloads$ cat nginx/Dockerfile
FROM nginx
RUN echo '这是一个本地Nginx镜像' > /usr/share/nginx/html/index.html
senrsl@senrsl-ubuntu:~/Downloads$ docker build -t nginx:2021 nginx/
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM nginx
latest: Pulling from library/nginx
a076a628af6f: Pull complete
0732ab25fa22: Pull complete
d7f36f6fe38f: Pull complete
f72584a26f32: Pull complete
7125e4df9063: Pull complete
Digest: sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa
Status: Downloaded newer image for nginx:latest
---> f6d0b4767a6c
Step 2/2 : RUN echo '这是一个本地Nginx镜像' > /usr/share/nginx/html/index.html
---> Running in 7386280dd815
Removing intermediate container 7386280dd815
---> b2e005b42622
Successfully built b2e005b42622
Successfully tagged nginx:2021
senrsl@senrsl-ubuntu:~/Downloads$ ls -a
. .. clock nginx
senrsl@senrsl-ubuntu:~/Downloads$ ls -a nginx/
. .. Dockerfile
senrsl@senrsl-ubuntu:~/Downloads$
senrsl@senrsl-ubuntu:~/Downloads$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 2021 b2e005b42622 29 seconds ago 133MB
...
senrsl@senrsl-ubuntu:~/Downloads$
根据两行的Dockerfile文件,构建了一个镜像
运行试试
senrsl@senrsl-ubuntu:~/Downloads$ docker run -d -P nginx
2afc744042ca8cda775b01388685e472aea3ffdc879bdda8f79a6383c6782abe
senrsl@senrsl-ubuntu:~/Downloads$ docker port 2afc744042ca
80/tcp -> 0.0.0.0:49153
senrsl@senrsl-ubuntu:~/Downloads$
访问 http://192.168.7.89:49153/ 就看到了Welcome Nginx。。。。
择日 2021年04月15日11:25:48
senRsl
2021年04月06日17:39:36
没有评论 :
发表评论