仓库配置及安装启动

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum makecache fast
[root@localhost ~]# yum -y install docker-ce
[root@localhost ~]# service docker start
Redirecting to /bin/systemctl start docker.service

版本查看

[root@localhost ~]# docker -v
Docker version 18.09.0, build 4d60db4

镜像下载

[root@localhost ~]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
4fe2ade4980c: Pull complete
Digest: sha256:621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528
Status: Downloaded newer image for alpine:latest

查看的本地镜像

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 196d12cf6ab1 3 months ago 4.41MB

镜像启动成容器

[root@localhost ~]# docker run -it alpine sh
/ #

容器里创建一个大小为20M

/ # dd if=/dev/zero of=chenxi bs=10M count=2
2+0 records in
2+0 records out
/ # ls -l chenxi
-rw-r--r-- 1 root root 20971520 Dec 12 04:31 chenxi

用快捷键Ctrl+p,q退出容器,根据此运行的容器制作镜像

[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
292d32b4b3a1 alpine "sh" 15 minutes ago Up 15 minutes condescending_wu
[root@localhost ~]# docker commit 292d32b4b3a1 chenxi:test
sha256:cfcb3e42b392ac74fb8984f339916cbd062a968f6398af47e24d55dbb4364152
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
chenxi test cfcb3e42b392 13 seconds ago 25.4MB
alpine latest 196d12cf6ab1 3 months ago 4.41MB

查看镜像层

[root@localhost ~]# docker history  alpine:latest
IMAGE CREATED CREATED BY SIZE COMMENT
196d12cf6ab1 3 months ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 3 months ago /bin/sh -c #(nop) ADD file:25c10b1d1b41d46a1… 4.41MB
[root@localhost ~]# docker history chenxi:test
IMAGE CREATED CREATED BY SIZE COMMENT
cfcb3e42b392 2 minutes ago sh 21MB
196d12cf6ab1 3 months ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 3 months ago /bin/sh -c #(nop) ADD file:25c10b1d1b41d46a1… 4.41MB

使用dockerfil简单构建tomcat镜像文件

[root@localhost ~]# ls /tomcat/
apache-tomcat-9.0.13.tar.gz Dockerfile
[root@localhost ~]# cat /tomcat/Dockerfile
FROM centos
RUN mkdir /tomcat && yum -y install java
COPY apache-tomcat-9.0.13.tar.gz /tomcat
RUN tar -zvxf /tomcat/apache-tomcat-9.0.13.tar.gz -C /usr/local/
EXPOSE 8080
CMD ["/usr/local/apache-tomcat-9.0.13/bin/catalina.sh", "run"] [root@localhost tomcat]# docker build -f Dockerfile -t tomcat:chenxi .
Sending build context to Docker daemon 9.991MB
Step 1/6 : FROM centos
---> 1e1148e4cc2c
Step 2/6 : RUN mkdir /tomcat && yum -y install java
---> Using cache
---> 05e991a5d3f7
Step 3/6 : COPY apache-tomcat-9.0.13.tar.gz /tomcat
---> Using cache
---> 3dffdd201d5f
Step 4/6 : RUN tar -zvxf /tomcat/apache-tomcat-9.0.13.tar.gz -C /usr/local/
---> Using cache
---> 1b8021e0f9fb
Step 5/6 : EXPOSE 8080
---> Using cache
---> a3d6bc853d8c
Step 6/6 : CMD ["/usr/local/apache-tomcat-9.0.13/bin/catalina.sh", "run"]
---> Using cache
---> 3969b96f4e53
Successfully built 3969b96f4e53
Successfully tagged tomcat:chenxi

查看构建的容器镜像并启动

[root@localhost tomcat]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 7 3969b96f4e53 7 minutes ago 445MB
tomcat chenxi 3969b96f4e53 7 minutes ago 445MB
<none> <none> 2b60cff33319 2 days ago 435MB
<none> <none> 0717bf973613 2 days ago 435MB
centos latest 1e1148e4cc2c 8 days ago 202MB
[root@localhost tomcat]# docker run -d --name chenxi -p 8080:8080 tomcat:chenxi
a7713ecd235158cdc7c276d057a8fb06561002f119d80b6ee882810e1d3c8488
[root@localhost tomcat]# ss -lntp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
users:(("sshd",pid=1022,fd=3))LISTEN 0 100 127.0.0.1:25 *:*
users:(("master",pid=1293,fd=13))LISTEN 0 128 :::8080 :::*
users:(("docker-proxy",pid=2259,fd=4))LISTEN 0 128 :::22 :::*
users:(("sshd",pid=1022,fd=4))LISTEN 0 100 ::1:25 :::*
users:(("master",pid=1293,fd=14))

  

最新文章

  1. Unix时间戳
  2. rabbitMQ中vhost虚拟主机的理解
  3. 分享书籍[writing idiomatic python ebook]
  4. github 上传或删除 文件 命令
  5. WPF动画
  6. 一道来自华为的C机试题目
  7. Codeforces Round#2
  8. 安卓---android:versionCode和android:versionName 用途
  9. Rabbitmq集群高可用部署详细
  10. Nodejs express 获取url参数,post参数的三种方式
  11. android webview和 javascript 进行交互
  12. docker学习构建镜像---第三章节
  13. kbmmw中向服务器端传递对象的一种简单方式
  14. setting.xml配置文件
  15. Android MediaPlayer架构 -- 前言小知识点(一)
  16. C# 后台获取API接口数据
  17. ICTCLAS中的HMM人名识别
  18. 每日英语:Got 5 Minutes? &#39;Flash Fiction&#39; Catches On
  19. Android Studio怎样加入工程(project)为library(针对非gradle)
  20. win7 64位下android开发环境的搭建

热门文章

  1. logging日志类
  2. JAVA基础-面向对象06
  3. E20180418-hm
  4. hdoj5818【模拟】
  5. poj2239 poj1274【二分匹配】
  6. python __builtins__ type类 (69)
  7. apcloud混合式开发app学习笔记
  8. Oracle数据库创建表空间及用户授权
  9. autolayout UIImageView 根据 UILabel的宽度变换位置
  10. CGI、ASP、PHP、JSP、 ASP.NET网站开发语言比较