首页 >> 大全

docker

2023-12-20 大全 27 作者:考证青年

26--:

用来构建镜像的文件!命令参数脚本!

步骤:

1、编写一个文件

2、 build构建成为一个镜像

3、 run 运行镜像

4、 push 发布镜像(,阿里云镜像仓库)

构建过程

基础知识指令:

1、每个保留关键字(指令)都必须是大写字母

2、执行从上到下顺序执行

3、#表示注释

4、每一个指令都会创建提交一个新的镜像层,并提交!

是面向开发的,我们以后要发布项目,做镜像,就需要编写文件.

镜像逐渐成为企业交付的标准,必掌握!

:构建文件,定义了一切的步骤,源代码

:通过构建生成的镜像,最终发布和运行的产品!

容器:容器就是镜像运行起来提供服务器

指令

CMD :指定这个容器启动的时候要运行的命名,只有最后一个会生效,可被替代

: 指定这个容器启动的时候要运行的命名,可以追加命令

:当构建一个被集成的这个时候就会运行的命令,出发指令。

COPY:复制,类似ADD,将文件cp到镜像中

ENV:构建的时候设置环境变量

测试:

创建自己的

1./home/

2.vim -,给添加ll,等命令

FROM centos
MAINTAINER zh-test<1069875886@qq.com>ENV MYPATH /usr/local
WORKDIR $MYPATHRUN yum -y install vim
RUN yum -y install net-toolsEXPOSE 80CMD echo $MYAPTH
CMD echo "=====end====="
CMD /bin/bash

3、通过这个文件构建一个镜像

docker build -f dockerfile文件路径名 -t 镜像名:[tag] .
[root@hadoop106 dockerfile]# docker build -f mydockerfile-centos -t mycentos:0.1 .

4.测试运行

run -it :0.1

查看本地的变更历史

镜像id

CMD和区别

CMD :指定这个容器启动的时候要运行的命名,只有最后一个会生效,可被替代

: 指定这个容器启动的时候要运行的命名,可以追加命令

vim -cmd-test

run之后生效了。CMD覆盖了,不能追加。 可以追加。

制作镜像:

1、准备和jdk

2、编写文件

FROM centos
MAINTAINER zh<1069875886@11.com>
COPY readme.txt /uer/local/readme.txt
ADD jdk-8u212-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.50.tar.gz /usr/local/RUN yum -y install vim
ENV MYPATH /usr/local
WORKDIR $MYPATHENV JAVA_HOME /usr/local/jdk/1.8.0_212
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.50
ENV CATALINA_BASH /usr/local/apache-tomcat-9.0.50
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_BASH/binEXPOSE 8080CMD /usr/local/apache-tomcat-9.0.50/bin/startup.sh && tail -F /url/local/apache-tomcat-9.0.50/bin/logs/cataline.out

3、构建镜像

docker build -t mytomcat-v1 .

4、启动镜像

docker run -d -p 9090:8080 --name mytomcat-test -v /home/tomcat-self/build/tomcat/test:/url/local/apache-tomcat-9.0.50/webapps/test -v /home/tomcat-self/build/tomcat/logs/:/url/local/apache-tomcat-9.0.50/logs mytomcat-v1

5、访问测试

6、发布测试(卷挂载,本地可直接发布)

发布到(自行百度,了解)

1.地址htps:///注册自己的账号!

2.确定这个这账号可以登录

3.在我们服务器上提交自己的镜像

[root@hadoop106 tomcat-self]# docker login --he1p
usage: docker login [OPTIONS] [SERVER]
L0g in to a Docker registry.
If no server is specified, the defau1t is defined by the daemon.
options:
-p,--password string
Password 
--password-stdin
Take the password from stdin
-u,--username string Us ername
[root@hadoop106 tomcat-self]#docker login -u test -p 123
login successed

4、登录完毕后就可以提交镜像了,就是一步 push

push 作者/镜像名:版本号

# push镜像的问题9
[root@hadoop106 tomcat-self]# docker push teset/mytomcat:1.0
The push refers to repos itory [docker. io/teset/mytomcat]
An image does not exist 1ocally with the tag: teset/ mytomcat
#解决,增加一个tag
[root@hadoop106 tomcat-self]# docker tag f8559daf1fc2 mytomcat/tomcat:1.0
# docker psuh上去即可!自己发布的镜像尽量带上版本号
[root@kuangshen tomcat]# docker push mytomcat/tomcat:1.0
The push refers to reposi tory [docker. io/mytomcat/tomcat]
fcc7fccb8e04: Preparing
b5577f344233: Preparing
bdcb94365850: Prepar ing
1c5bd81521f5: Preparing
0683de282177: Preparing

小结:

参考来自:

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了