docker实验

1.Docker安装部署
(1).关闭防火墙
(2).更新源
(3)设置Docker仓库
(4)启动docker
(5)查看版本:
2.Docker pull 容器并运行服务;

拉取nginx镜像,运行该nginx实例

访问 web 页面 192.168.16.16:8080

docker ps

docker exec -it efe8484c1ca2 /bin/bash

更换镜像阿里源

echo "">sources.list

echo "deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib">>sources.list

echo "deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib">>sources.list

echo "deb http://mirrors.aliyun.com/debian-security stretch/updates main">>sources.list

echo "deb-src http://mirrors.aliyun.com/debian-security stretch/updates main">>sources.list

echo "deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib">>sources.list echo "deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib">>sources.list echo "deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib">>sources.list echo "deb-src http://mirrors.aliyun.com/debian/ stretch-backports main nonfree contrib">>sources.list

echo "deb https://deb.debian.org/debian buster main contrib nonfree">>sources.list

echo "deb-src https://deb.debian.org/debian buster main contrib nonfree">>sources.list

echo "deb https://deb.debian.org/debian buster-updates main contrib nonfree">>sources.list

echo "deb-src https://deb.debian.org/debian buster-updates main contrib nonfree">>sources.list echo "deb https://deb.debian.org/debian buster-backports main contrib nonfree">>sources.list

echo "deb-src https://deb.debian.org/debian buster-backports main contrib non-free">>sources.list 更新源 apt-get update

安装 vim apt-get install vim

修改 index.html 为自己的学号和姓名(https://registry.hub.docker.com/_/nginx)

cd /usr/share/nginx/html

3.Dockerfile和Docker build定制容器;dockerfile内容显示,docker build过程截图

拉取镜像、编写 dockerfile

docker pull ubuntu:16.04

mkdir baseos

cd baseos

touch Dockerfile

vi Dockerfile

Base os image FROM ubuntu:16.04

MAINTAINER your_name <your_email_address>

LABEL Description="This image is the base os images." Version="1.0"

reconfig timezone

RUN echo "Asia/Shanghai" > /etc/timezone

docker build -t chenzhiyong/baseos:1.0 .

docker images

构建 jre 基础镜像

下载 jdk,解压,将文件中的 jre 打包

sudo mv jre jre1.8.0_321

sudo tar -zcvf jre-8u321-linux-x64.tar.gz jre1.8.0_321

sudo mkdir jre-8u321 sudo cp jre-8u321-linux-x64.tar.gz jre-8u321

cd jre-8u321/

sudo vi Dockerfile

Base jre image

FROM xjli/baseos:1.0

MAINTAINER your_name

LABEL Description="This image is used to serve Oracle jre 7u80" Version="1.0"

Install and config Oracle jre

ADD jre-8u321-linux-x64.tar.gz /usr/lib/jvm/

RUN update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.8.0_321/bin/java" 1 \

&& update-alternatives --set java /usr/lib/jvm/jre1.8.0_321/bin/java

ENV JAVA_HOME /usr/lib/jvm/jre1.8.0_321

构建 jre 镜像

docker build -t xjli/jre:8u321 .

检查版本 --rm 选项可以在容器运行完毕立即删除容器。

docker run --rm xjli/jre:8u321 java -version

构建 tomcat 基础镜像

mkdir tomcat7-jre7

cp apache-tomcat-7.0.77.tar.gz tomcat7-jre7/

cd tomcat7-jre7/

vi Dockerfile

Base image

FROM xjli/jre:8u321

MAINTAINER your_name <your_email_address>

LABEL Description="This image is used to run tomcat7 with jre7." Version="1.0"

#把 tomcat 添加到容器中

ADD apache-tomcat-7.0.77.tar.gz /usr/local

ENV CLASSPATH JAVA_HOME/lib/dt.jar:JAVA_HOME/lib/tools.jar

#配置 tomcat 环境变量

ENV CATALTNA_HOME /usr/local/apache-tomcat-7.0.77

ENV PATH PATH:JAVA_HOME/bin:$CATALTNA_HOME/bin

#设置工作目录

WORKDIR $CATALTNA_HOME

#容器端口

EXPOSE 8080 ENTRYPOINT ["catalina.sh","run"]

docker build -t xjli/tomcat:7-jre7 .

docker run -d --name mytomcat1 -p 10086:8080 xjli/tomcat:7-jre7 container:2d044b41600f

相关推荐
小小管写大大码8 小时前
如何让vscode变得更智能?vscode接入claude实现自动编程
运维·ide·vscode·自动化·编辑器·ai编程·腾讯云ai代码助手
zhang133830890759 小时前
CG-09H 超声波风速风向传感器 加热型 ABS材质 重量轻 没有机械部件
大数据·运维·网络·人工智能·自动化
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.10 小时前
Keepalived VIP迁移邮件告警配置指南
运维·服务器·笔记
物联网软硬件开发-轨物科技10 小时前
【轨物洞见】告别“被动维修”!预测性运维如何重塑老旧电站的资产价值?
运维·人工智能
程序员允诺10 小时前
[DevOps实战] 彻底解决依赖地狱:如何编译全静态、可移植的 Xorriso 工具
运维·devops
酣大智10 小时前
接口模式参数
运维·网络·网络协议·tcp/ip
一只自律的鸡11 小时前
【Linux驱动】bug处理 ens33找不到IP
linux·运维·bug
!chen11 小时前
linux服务器静默安装Oracle26ai
linux·运维·服务器
莫大33011 小时前
2核2G云服务器PHP8.5+MySQL9.0+Nginx(LNMP)安装WordPress网站详细教程
运维·服务器·nginx
刚刚入门的菜鸟11 小时前
php-curl
运维·web安全·php