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

相关推荐
运维_攻城狮6 分钟前
Nexus 3.x 私服搭建与运维完全指南(Maven 实战)
java·运维·maven
梁正雄10 分钟前
linux-shell-基础与变量和运算符-1
linux·运维
意疏13 分钟前
《金仓KingbaseES vs 达梦DM:从迁移到运维的全维度TCO实测对比》
运维
shawnyz17 分钟前
rhcse----DNS
运维·服务器
☆璇22 分钟前
【Linux】Reactor反应堆模式
linux·运维·服务器·网络
拾心2122 分钟前
【云运维】zabbix管理(续)
运维·zabbix
做运维的阿瑞35 分钟前
Kubernetes 原生滚动更新(Rolling Update)完整实践指南
云原生·容器·kubernetes
半桔36 分钟前
【IO多路转接】epoll 高性能网络编程:从底层机制到服务器实战
linux·运维·服务器·网络·php
刘某的Cloud38 分钟前
openvswitch-ovs-流表
linux·运维·openstack·系统·neutron·openvswitch
Yiiz.43 分钟前
RHCE练习
运维