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

相关推荐
Dragon水魅5 小时前
爬虫技术详解:从传统爬虫到浏览器自动化——以豆瓣读书笔记为例
运维·爬虫·自动化
willhuo6 小时前
# 自动化数据采集技术研究与实现:基于Playwright的抖音网页自动化方案
运维·selenium·c#·自动化·chrome devtools·webview
IP老炮不瞎唠6 小时前
IP轮换机制解析:动态住宅代理如何维持高可用率?
运维·服务器·网络
一个扣子6 小时前
OpenClaw 运维完全手册|日志分析、实时监控与故障排查指南
运维·监控·故障排查·健康检查·openclaw·clawmetry·openclawdoctor
Lentou6 小时前
nginx反向代理
运维·nginx
刘~浪地球6 小时前
API 安全设计最佳实践
运维·网络·安全
SilentSamsara6 小时前
存储卷体系:EmptyDir/HostPath/PV/PVC/StorageClass 的选型决策树
服务器·微服务·云原生·容器·架构·kubernetes·k8s
网络安全许木6 小时前
自学渗透测试第20天(防火墙基础与规则配置)
运维·服务器·网络·网络安全·渗透测试
亚空间仓鼠6 小时前
Docker 容器技术入门与实践 (二):Dockerfile文件
运维·docker·容器
遇见火星6 小时前
linux设置开启启动服务
linux·运维·服务器·nginx