赞
踩
Dockerfile
Docker镜像
Docker容器
Docker整体结构图
FROM centos:7
MAINTAINER tianxincoord@163.com
ENV WORK /opt
RUN yum -y install vim
CMD echo "vim编辑器安装完成"
RUN yum -y install net-tools
CMD echo "网络工具安装完成"
WORKDIR $WORK
CMD echo "工具目录设置完成"
EXPOSE 80
CMD /bin/bash
......
# 构建成功消息
Successfully built a1467c43b30c
Successfully tagged tianxin/centos:1.0
# 构建成功后查看镜像
[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tianxin/centos 1.0 a1467c43b30c 9 seconds ago 515MB
redis latest aa4d65e670d6 2 weeks ago 105MB
mysql 5.7 8cf625070931 2 weeks ago 448MB
centos 7 8652b9f0cb4c 8 months ago 204MB
[root@localhost docker]# docker run -it --name tianxin-centos tianxin/centos:1.0 [root@3e307a37f9ac opt]# pwd /opt [root@3e307a37f9ac opt]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.17.0.4 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:ac:11:00:04 txqueuelen 0 (Ethernet) RX packets 8 bytes 656 (656.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost redis]# docker history a1467c43b30c
IMAGE CREATED CREATED BY SIZE
a1467c43b30c 14 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "/bin… 0B
fac2dd7bdf3c 14 minutes ago /bin/sh -c #(nop) EXPOSE 80 0B
6ed0b3d96497 14 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo… 0B
6279934b0024 14 minutes ago /bin/sh -c #(nop) WORKDIR /opt 0B
ed95908c5c7b 14 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo… 0B
abd1744d570e 14 minutes ago /bin/sh -c yum -y install net-tools 128MB
4a7efc540d58 14 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "echo… 0B
d9ce990fb919 14 minutes ago /bin/sh -c yum -y install vim 183MB
42b4307fde4f 15 minutes ago /bin/sh -c #(nop) ENV WORK=/opt 0B
54a76e7e02be 15 minutes ago /bin/sh -c #(nop) MAINTAINER tianxincoord@1… 0B
8652b9f0cb4c 8 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 8 months ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> 8 months ago /bin/sh -c #(nop) ADD file:b3ebbe8bd304723d4… 204MB
[root@localhost redis]# ll
total 2472
-rw-r--r--. 1 root root 0 Aug 7 07:50 Dockerfile
-rw-r--r--. 1 root root 2465302 Jul 21 18:51 redis-6.2.5.tar.gz
-rw-r--r--. 1 root root 62186 Aug 7 08:02 redis.conf
# 设置基础信息 FROM centos:7 # 拷贝安装文件(先确保Dockerfile同级目录含有安装文件) ADD redis-6.2.5.tar.gz /opt/ # 进入工作目录 WORKDIR /opt/redis-6.2.5/src/ # 安装redis所需依赖 RUN yum -y install gcc gcc-c++ tcl automake autoconf libtool make # 编译和安装 RUN make RUN make install # 清除中间文件 RUN make distclean # 切换工作目录 WORKDIR /opt/redis-6.2.5/ # 删除原始配置文件 RUN rm -f redis.conf # 拷贝新redis文件 COPY redis.conf /opt/redis-6.2.5/ WORKDIR /opt/redis-6.2.5/src/ # 暴露端口 EXPOSE 6379 # 默认启动服务,可以启动容器时覆盖命令 CMD ["redis-server"]
docker build -t tianxin/redis .
docker run -d --name redis02 -p 6380:6379 tianxin/redis
docker pull centos:7
FROM centos:7
MAINTAINER tianxincoord@163.com
RUN mkdir /usr/local/jdk
WORKDIR /usr/local/jdk
ADD jdk-8u251-linux-x64.tar.gz /usr/local/jdk
ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_251
ENV JRE_HOME /usr/local/jdk/jdk1.8.0_251/jre
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
ENV PATH $JAVA_HOME/bin:$PATH
EXPOSE 80
# docker build -t java:8 . Sending build context to Docker daemon 195.1MB Step 1/10 : FROM centos:7 ---> eeb6ee3f44bd Step 2/10 : MAINTAINER tianxincoord@163.com ---> Running in 045e51b633e2 Removing intermediate container 045e51b633e2 ---> aaa06e3b387b Step 3/10 : RUN mkdir /usr/local/jdk ---> Running in 138074b4eec0 Removing intermediate container 138074b4eec0 ---> bf5cdee73362 Step 4/10 : WORKDIR /usr/local/jdk ---> Running in 251e26d7be7f Removing intermediate container 251e26d7be7f ---> 3324c3cc346c Step 5/10 : ADD jdk-8u251-linux-x64.tar.gz /usr/local/jdk ---> d82f82248fc6 Step 6/10 : ENV JAVA_HOME /usr/local/jdk/jdk1.8.0_251 ---> Running in 81b46ea286be Removing intermediate container 81b46ea286be ---> ba1f722dd501 Step 7/10 : ENV JRE_HOME /usr/local/jdk/jdk1.8.0_251/jre ---> Running in 2905af64f88c Removing intermediate container 2905af64f88c ---> c4f00b71b7f1 Step 8/10 : ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH ---> Running in 9e27b3d384d1 Removing intermediate container 9e27b3d384d1 ---> 768a812042b2 Step 9/10 : ENV PATH $JAVA_HOME/bin:$PATH ---> Running in b33cbb2e1213 Removing intermediate container b33cbb2e1213 ---> 75325c4bd9f2 Step 10/10 : EXPOSE 80 ---> Running in c55b08485621 Removing intermediate container c55b08485621 ---> 95064f52c03b Successfully built 95064f52c03b Successfully tagged java:8 See 'docker --help' [root@server01 jdk]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE # 完成的镜像 java 8 95064f52c03b 14 seconds ago 610MB centos 7 eeb6ee3f44bd 6 months ago 204MB
# 进入容器内部
# docker run -it --name java8 java:8
# 查看java版本
[root@4fc4e341d672 jdk]# java -version
# jdk安装成功
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
[root@4fc4e341d672 jdk]# pwd
/usr/local/jdk
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。