# 引用
FROM centos
# 作者信息
MAINTAINER vitcloud<vitcluod@163.com>
# 运行环境路径
ENV MYPATH /usr/local
WORKDIR $MYPATH
# java软件环境
# 配置java环境目录
ENV JAVA_HOME /usr/local/jdk1.8.0_191
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
# 配置tomcat环境目录
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.58
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.58
# path路径
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
# 安装第三方
RUN yum -y install vim # vim
RUN yum -y install net-tools # 网络
# python
RUN pip install flsk
# 暴露端口
EXPOSE 80
# 输出
CMD echo "------end------"
# 执行指令
CMD /bin/bash # 只有最后一个会生效,可被替代
ENTRYPOINT ["ls","-a"] # 可以追加命令
Dockerfile
FROM centos
MAINTAINER vitcloud<vitcluod@163.com>
ENV MYPATH /usr/local
WORKDIR $MYPATH
RUN yum -y install vim
RUN yum -y install net-tools
# 暴露端口
EXPOSE 80
CMD echo "------end------"
CMD /bin/bash
名字
:centos-base(若带版本 centos-base:1.0)-f
: dockerfile地址()
docker build -f ./Dockerfile -t centos-base .
docker build -f ./Dockerfile -t centos-base:1.0 .
docker run -it centos-base
Dockerfile
FROM centos
MAINTAINER vitcloud<vitcloud@163.com>
COPY readme.txt /usr/local/readme.txt
# 添加 软件包
ADD jdk-8u191-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.58.tar.gz /usr/local/
# 安装vim
RUN yum -y install vim
# 配置环境目录
ENV MYPATH /usr/lcoal
WORKDIR $MYPATH
# 配置java环境目录
ENV JAVA_HOME /usr/local/jdk1.8.0_191
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
# 配置tomcat环境目录
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.58
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.58
# path路径
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
# 暴露端口
EXPOSE 8080
# 运行脚本
CMD /usr/local/apache-tomcat-9.0.58/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.58/bin/logs/catalina.out
docker build -t vitcloud-tomcat .
docker run -d -p 9090:8080 \
-v /usr/local/docker-build/tomcat/test:/usr/local/apache-tomcat-9.0.58/webapps/test \
-v /home/vitcloud-docker-build/tomcatlogs/:/usr/local/apache-tomcat-9.0.58/logs \
--name blog-tomcat \
vitcloud-tomcat
交互方式进入
docker exec -it 654c26bc7abb /bin/bash
由于做了卷挂载,我们字节在本地编写项目就可以发布了
<web-app version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID">
</web-app>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>云间来客</title>
</head>
<body>
<div>测试日志</div>
</body>
</html>
Dockerfile
https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz
FROM centos:7.6.1810
MAINTAINER vitcloud<vitcloud@163.com>
RUN set -ex \
# 预安装所需组件
&& yum install -y wget tar libffi-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make initscripts \
&& wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgz \
&& tar -zxvf Python-3.8.5.tgz \
&& cd Python-3.8.5 \
&& ./configure prefix=/usr/local/python3 \
&& make \
&& make install \
&& make clean \
&& rm -rf /Python-3.8.5* \
&& yum install -y epel-release \
&& yum install -y python-pip
# 设置默认为python3
RUN set -ex \
# 备份旧版本python
&& mv /usr/bin/python /usr/bin/python27 \
&& mv /usr/bin/pip /usr/bin/pip27 \
# 配置默认为python3
&& ln -s /usr/local/python3/bin/python3.8 /usr/bin/python \
&& ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
# 修复因修改python版本导致yum失效问题
RUN set -ex \
&& sed -i "s#/usr/bin/python#/usr/bin/python2.7#" /usr/bin/yum \
&& sed -i "s#/usr/bin/python#/usr/bin/python2.7#" /usr/libexec/urlgrabber-ext-down \
&& yum install -y deltarpm
# 基础环境配置
RUN set -ex \
# 修改系统时区为东八区
&& rm -rf /etc/localtime \
&& ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& yum install -y vim \
# 安装定时任务组件
&& yum -y install cronie
# 支持中文
RUN yum install kde-l10n-Chinese -y
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
# 更新pip版本
RUN pip install --upgrade pip
ENV LC_ALL zh_CN.UTF-8
docker build -t centos7-python38 .
docker run -itd \
--restart always --privileged=true \
-v /root/dockers/python:/root/python \
-v /root/dockers/python/cron:/var/spool/cron /usr/sbin/init
python:37
--name python
docker commit 提交同期成为一个副本
# 命令和git原理类似
docker commit -m="提交的描述信息" -a="作者" 容器id 目标镜像名:[TAG]
案例
docker commit -a="有勇气的牛排" -m="add webapps app" 48629b5a69d2 tomcat02:1.0
DockerHub
地址:https://hub.docker.com/
# 帮助
docker login --help
# 登录
docker login -u 用户名
# 推动自己的镜像到 DockerHub
docker push vitcloud/tomcat:1.0
给镜像添加tag
docker tag d89b35c35d33 vitcloud/tomcat:1.0
发布到阿里云镜像服务
创建命名空间
创建容器镜像服务
创建命名空间
创建容器镜像
浏览阿里云
# 登录阿里云
docker login --username=1809296387@qq.com registry.cn-zhangjiakou.aliyuncs.com
# 给镜像生成版本号
docker tag [ImageId] registry.cn-zhangjiakou.aliyuncs.com/warm-test/charles-test:[镜像版本号]
# 推送
docker push registry.cn-zhangjiakou.aliyuncs.com/warm-test/diytomcat:1.0
docker push vitcloud/tomcat:1.0
docker push registry.cn-zhangjiakou.aliyuncs.com/warm-test/charles-test:[镜像版本号]
将镜像保存到本地
docker save -o centos7-python38_2.0.tar centos7-python38:2.0
加载本地镜像
docker load -i centos7-python38_2.0.tar
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://vitcloud.blog.csdn.net/article/details/122738852
内容来源于网络,如有侵权,请联系作者删除!