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

相关推荐

  1. Docker实战

    2024-05-15 15:10:10       50 阅读
  2. docker实战:安装redis

    2024-05-15 15:10:10       69 阅读
  3. 5.docker实战

    2024-05-15 15:10:10       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-15 15:10:10       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-15 15:10:10       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-15 15:10:10       82 阅读
  4. Python语言-面向对象

    2024-05-15 15:10:10       91 阅读

热门阅读

  1. c# 几何图形编程接口

    2024-05-15 15:10:10       31 阅读
  2. rk3568 移植rk628

    2024-05-15 15:10:10       32 阅读
  3. 深度学习学习日记5.14

    2024-05-15 15:10:10       33 阅读
  4. C++ QT设计模式:责任链模式

    2024-05-15 15:10:10       34 阅读
  5. Linux基础知识面试题

    2024-05-15 15:10:10       26 阅读
  6. Auto.js 开发入门

    2024-05-15 15:10:10       29 阅读
  7. 数据库面试题(MySQL、Oracle)

    2024-05-15 15:10:10       30 阅读
  8. C++多态

    C++多态

    2024-05-15 15:10:10      27 阅读
  9. Python自动化测试实战:深入Page Object模式

    2024-05-15 15:10:10       35 阅读
  10. IT行业现状与未来趋势:洞察变革的浪潮

    2024-05-15 15:10:10       35 阅读