docker学习(二)之应用部署、dockfile镜像制作
1、docker应用部署
1.1 部署mysql
- 搜索mysql镜像
[root@docker ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 9375 [OK]
mariadb MariaDB is a community-developed fork of MyS… 3370 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 687 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 74
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 66
centurylink/mysql Image containing mysql. Optimized to be link… 61 [OK]
deitch/mysql-backup REPLACED! Please use http://hub.docker.com/r… 41 [OK]
bitnami/mysql Bitnami MySQL Docker Image 38 [OK]
tutum/mysql Base docker image to run a MySQL database se… 34
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 29 [OK]
prom/mysqld-exporter 27 [OK]
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 25
centos/mysql-56-centos7 MySQL 5.6 SQL database server 19
circleci/mysql MySQL is a widely used, open-source relation… 19
mysql/mysql-router MySQL Router provides transparent routing be… 15
databack/mysql-backup Back up mysql databases to... anywhere! 14
arey/mysql-client Run a MySQL client from a docker container 13 [OK]
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 6 [OK]
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
genschsa/mysql-employees MySQL Employee Sample Database 5 [OK]
devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici… 3
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
jelastic/mysql An image of the MySQL database server mainta… 1
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 0 [OK]
monasca/mysql-init A minimal decoupled init container for mysql 0
- 拉取mysql镜像
[root@docker ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
c499e6d256d6: Already exists
22c4cdf4ea75: Pull complete
6ff5091a5a30: Pull complete
2fd3d1af9403: Pull complete
0d9d26127d1d: Pull complete
54a67d4e7579: Pull complete
fe989230d866: Pull complete
3a808704d40c: Pull complete
826517d07519: Pull complete
69cd125db928: Pull complete
b5c43b8c2879: Pull complete
1811572b5ea5: Pull complete
Digest: sha256:b69d0b62d02ee1eba8c7aeb32eba1bb678b6cfa4ccfb211a5d7931c7755dc4a8
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
docker.io/library/mysql:latest
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 4cdbec704e47 2 weeks ago 98.2MB
mysql latest 9228ee8bac7a 2 weeks ago 547MB
centos latest 470671670cac 2 months ago 237MB
- 创建容器
创建宿主机mysql目录
[root@docker ~]# mkdir ~/mysql
[root@docker ~]# cd ~/mysql
[root@docker mysql]#
[root@docker mysql]# docker run -id -p 3307:3306 --name=c_mysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
f2ff2f76f2cae07aab7fb85d86adcfa0828aa7ccc38e503c7bd7dda3b3fd9758
[root@docker mysql]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f2ff2f76f2ca mysql "docker-entrypoint.s…" 11 seconds ago Up 9 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp c_mysql
4ce9f3321cc6 centos "/bin/bash" 29 minutes ago Up 29 minutes c2
d2982f3ba596 centos "/bin/bash" 29 minutes ago Up 29 minutes c1
68f6bd67ee3c centos "/bin/bash" 31 minutes ago Up 31 minutes c3
[root@docker mysql]#
- 操作容器中的mysql
[root@docker mysql]# docker exec -it c_mysql /bin/bash
root@f2ff2f76f2ca:/# mysql -u root -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
mysql> create databse db1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'databse db1' at line 1
mysql> create database db1;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| db1 |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>
- 远端验证mysql
这里我们可以使用sqlyog工具来连接
在db1库中创建user表
插入数据到user表中
进入到容器里查询db1中的user表信息
[root@docker mysql]# docker exec -it c_mysql /bin/bash
root@f2ff2f76f2ca:/# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.19 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use db1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from user;
+----+----------+----------+
| id | username | password |
+----+----------+----------+
| 1 | davie67 | 123456 |
| 2 | tt | tt |
+----+----------+----------+
2 rows in set (0.00 sec)
mysql>
MySQL部署
- 容器内的网络服务和外部机器不能直接通信
- 外部机器和宿主机可以通过通信
- 宿主机和容器可以直接通信
- 当容器中的网络服务需要被外部机器访问时,可以将容器中提供服务的端口映射到宿主机的端口上。外部机器访问宿主机的该端口,从而间接访问容器的服务
- 这种操作称为:端口映射
1.2 部署tomcat
- 搜索tomcat镜像
[root@docker data]# docker search tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementati… 2698 [OK]
tomee Apache TomEE is an all-Apache Java EE certif… 77 [OK]
dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base… 53 [OK]
bitnami/tomcat Bitnami Tomcat Docker Image 31 [OK]
kubeguide/tomcat-app Tomcat image for Chapter 1 28
consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 17 [OK]
cloudesire/tomcat Tomcat server, 6/7/8 15 [OK]
aallam/tomcat-mysql Debian, Oracle JDK, Tomcat & MySQL 12 [OK]
arm32v7/tomcat Apache Tomcat is an open source implementati… 10
rightctrl/tomcat CentOS , Oracle Java, tomcat application ssl… 6 [OK]
maluuba/tomcat7-java8 Tomcat7 with java8. 4
unidata/tomcat-docker Security-hardened Tomcat Docker container. 4 [OK]
amd64/tomcat Apache Tomcat is an open source implementati… 2
jelastic/tomcat An image of the Tomcat Java application serv… 2
arm64v8/tomcat Apache Tomcat is an open source implementati… 2
i386/tomcat Apache Tomcat is an open source implementati… 1
camptocamp/tomcat-logback Docker image for tomcat with logback integra… 1 [OK]
99taxis/tomcat7 Tomcat7 1 [OK]
oobsri/tomcat8 Testing CI Jobs with different names. 1
ppc64le/tomcat Apache Tomcat is an open source implementati… 1
secoresearch/tomcat-varnish Tomcat and Varnish 5.0 0 [OK]
picoded/tomcat7 tomcat7 with jre8 and MANAGER_USER / MANAGER… 0 [OK]
s390x/tomcat Apache Tomcat is an open source implementati… 0
cfje/tomcat-resource Tomcat Concourse Resource 0
appsvc/tomcat
- 拉取tomcat镜像
[root@docker data]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
f15005b0235f: Pull complete
41ebfd3d2fd0: Pull complete
b998346ba308: Pull complete
f01ec562c947: Pull complete
74c11ae3efe8: Pull complete
3a7e595a3ef5: Pull complete
208407758d73: Pull complete
b5238120a381: Pull complete
33cc051e8b8b: Pull complete
d34ad36ee405: Pull complete
Digest: sha256:89d20858a7a6696b7d5f728cb4283106b867abe7b8579d80c0b4715af9a580ac
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
- 创建tomcat容器
[root@docker ~]# mkdir tomcat
[root@docker ~]# cd tomcat/
[root@docker tomcat]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f2ff2f76f2ca mysql "docker-entrypoint.s…" 43 minutes ago Up 43 minutes 33060/tcp, 0.0.0.0:3307->3306/tcp c_mysql
4ce9f3321cc6 centos "/bin/bash" About an hour ago Up About an hour c2
d2982f3ba596 centos "/bin/bash" About an hour ago Up About an hour c1
68f6bd67ee3c centos "/bin/bash" About an hour ago Up About an hour c3
[root@docker tomcat]# docker run -id --name=c_tomcat -p 8080:8080 -v $PWD:/usr/local/tomcat/webapps tomcat
9c946a828a7bb4c66ad76612a715cd7e0b19c00cbec8147deb163cab25322db9
[root@docker tomcat]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c946a828a7b tomcat "catalina.sh run" 4 seconds ago Up 3 seconds 0.0.0.0:8080->8080/tcp c_tomcat
f2ff2f76f2ca mysql "docker-entrypoint.s…" 44 minutes ago Up 44 minutes 33060/tcp, 0.0.0.0:3307->3306/tcp c_mysql
4ce9f3321cc6 centos "/bin/bash" About an hour ago Up About an hour c2
d2982f3ba596 centos "/bin/bash" About an hour ago Up About an hour c1
68f6bd67ee3c centos "/bin/bash" About an hour ago Up About an hour
- 测试tomcat容器
[root@docker tomcat]# mkdir test
[root@docker tomcat]# echo '<h1>hello tomcat docker </h1>' > test/index.html
[root@docker tomcat]#
通过浏览器查看网页
1.3 部署nginx
- 搜索nginx镜像
[root@docker ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 12990 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1777 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 765 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 105
bitnami/nginx Bitnami nginx Docker Image 82 [OK]
tiangolo/nginx-rtmp Docker image with Nginx using the nginx-rtmp… 68 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy ho… 52
nginxdemos/hello NGINX webserver that serves a simple page co… 47 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager 38 [OK]
nginx/unit NGINX Unit is a dynamic web and application … 36
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 29
privatebin/nginx-fpm-alpine PrivateBin running on an Nginx, php-fpm & Al… 23 [OK]
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 18 [OK]
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 13
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 13
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 13 [OK]
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 13
raulr/nginx-wordpress Nginx front-end for the official wordpress:f… 12 [OK]
nginx/nginx-prometheus-exporter NGINX Prometheus Exporter 10
sophos/nginx-vts-exporter Simple server that scrapes Nginx vts stats a… 7 [OK]
mailu/nginx Mailu nginx frontend 6 [OK]
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 5 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 1 [OK]
wodby/nginx Generic nginx 0 [OK]
centos/nginx-110-centos7 Platform for running nginx 1.10 or building … 0
- 拉取nginx镜像
[root@docker ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
c499e6d256d6: Already exists
74cda408e262: Pull complete
ffadbd415ab7: Pull complete
Digest: sha256:a979c1425d292059fae1b35a7f60278a923160879f92cbe8877a951c32057cc1
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 6ab907c973d2 6 days ago 528MB
redis latest 4cdbec704e47 2 weeks ago 98.2MB
nginx latest ed21b7a8aee9 2 weeks ago 127MB
mysql latest 9228ee8bac7a 2 weeks ago 547MB
centos latest 470671670cac 2 months ago 237MB
- 创建nginx容器
宿主机上创建nginx目录
[root@docker ~]# mkdir nginx
[root@docker ~]# cd nginx
[root@docker nginx]# mkdir conf
[root@docker nginx]#
配置nginx.conf文件
[root@docker nginx]# cd conf
root@8432b8f74b6f:/# vim nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
创建nginx容器
[root@docker conf]# cd ..
[root@docker nginx]# docker run -id --name=c_nginx -p 80:80 -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/var/log/nginx -v $PWD/html:/usr/share/nginx/html nginx
3d784a114d161a567e3150b55d208dc669c9d66137599dd75e09c3d475dd5acf
[root@docker nginx]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3d784a114d16 nginx "nginx -g 'daemon of…" 5 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp c_nginx
9c946a828a7b tomcat "catalina.sh run" 44 minutes ago Up 44 minutes 0.0.0.0:8080->8080/tcp c_tomcat
f2ff2f76f2ca mysql "docker-entrypoint.s…" About an hour ago Up About an hour 33060/tcp, 0.0.0.0:3307->3306/tcp c_mysql
4ce9f3321cc6 centos "/bin/bash" 2 hours ago Up 2 hours c2
d2982f3ba596 centos "/bin/bash" 2 hours ago Up 2 hours c1
68f6bd67ee3c centos "/bin/bash" 2 hours ago Up 2 hours c3
- 测试nginx容器
[root@docker nginx]# ls
conf html logs
[root@docker nginx]# cd html
[root@docker html]# echo '<h1>hello nginx docker </h1>' > index.html
[root@docker html]# ls
index.html
1.4 部署redis
- 搜索redis镜像
[root@docker html]# docker search redis
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 8034 [OK]
bitnami/redis Bitnami Redis Docker Image 141 [OK]
sameersbn/redis 79 [OK]
grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0 & 5.0 65
rediscommander/redis-commander Alpine image for redis-commander - Redis man… 37 [OK]
kubeguide/redis-master redis-master with "Hello World!" 31
redislabs/redis Clustered in-memory database engine compatib… 24
oliver006/redis_exporter Prometheus Exporter for Redis Metrics. Supp… 21
redislabs/redisearch Redis With the RedisSearch module pre-loaded… 21
arm32v7/redis Redis is an open source key-value store that… 21
bitnami/redis-sentinel Bitnami Docker Image for Redis Sentinel 12 [OK]
webhippie/redis Docker images for Redis 11 [OK]
redislabs/redisgraph A graph database module for Redis 10 [OK]
s7anley/redis-sentinel-docker Redis Sentinel 9 [OK]
insready/redis-stat Docker image for the real-time Redis monitor… 9 [OK]
arm64v8/redis Redis is an open source key-value store that… 9
redislabs/redismod An automated build of redismod - latest Redi… 7 [OK]
redislabs/redisinsight RedisInsight - The GUI for Redis 5
centos/redis-32-centos7 Redis in-memory data structure store, used a… 5
circleci/redis CircleCI images for Redis 4 [OK]
clearlinux/redis Redis key-value data structure server with t… 2
tiredofit/redis Redis Server w/ Zabbix monitoring and S6 Ove… 1 [OK]
runnable/redis-stunnel stunnel to redis provided by linking contain… 1 [OK]
wodby/redis Redis container image with orchestration 1 [OK]
xetamus/redis-resource forked redis-resource 0 [OK]
- 拉取redis镜像
[root@docker html]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
Digest: sha256:a732b1359e338a539c25346a50bf0a501120c41dc248d868e546b33e32bf4fe4
Status: Image is up to date for redis:latest
docker.io/library/redis:latest
[root@docker html]# cd
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 6ab907c973d2 6 days ago 528MB
redis latest 4cdbec704e47 2 weeks ago 98.2MB
nginx latest ed21b7a8aee9 2 weeks ago 127MB
mysql latest 9228ee8bac7a 2 weeks ago 547MB
centos latest 470671670cac 2 months ago 237MB
- 创建redis容器
[root@docker ~]# docker run -id --name=c_redis -p 6379:6379 redis
7cc2987f8b9c9e6c72232415073f7aa7237bb356e727d7919671f271f2e72c39
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7cc2987f8b9c redis "docker-entrypoint.s…" 5 seconds ago Up 4 seconds 0.0.0.0:6379->6379/tcp c_redis
3d784a114d16 nginx "nginx -g 'daemon of…" 9 minutes ago Up 9 minutes 0.0.0.0:80->80/tcp c_nginx
9c946a828a7b tomcat "catalina.sh run" 53 minutes ago Up 53 minutes 0.0.0.0:8080->8080/tcp c_tomcat
f2ff2f76f2ca mysql "docker-entrypoint.s…" 2 hours ago Up 2 hours 33060/tcp, 0.0.0.0:3307->3306/tcp c_mysql
4ce9f3321cc6 centos "/bin/bash" 2 hours ago Up 2 hours c2
d2982f3ba596 centos "/bin/bash" 2 hours ago Up 2 hours c1
68f6bd67ee3c centos "/bin/bash" 2 hours ago Up 2 hours c3
- 测试redis容器
redis-cli.exe -h 192.168.8.20 -p 6379
2、dockerfile
2.1 docker镜像原理
思考:
- docker镜像本质是什么?
一个分层文件系统 - docker中一个centos镜像为什么只有200MB,而一个centos操作系统的iso文件要几个G?
centos的iso镜像文件包含bootfs和rootfs,而docker的centos镜像复用操作系统的bootfs,只有rootfs和其他镜像层 - dockers中一个tomcat镜像为什么有500MB,而一个tomcat安装包只有70多MB?
由于dockers中镜像是分层的,tomcat虽然只有70多MB,但它需要依赖于父镜像和基础镜像,所以整个对外暴露的tomcat镜像大小500多MB
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 6ab907c973d2 6 days ago 528MB
redis latest 4cdbec704e47 2 weeks ago 98.2MB
nginx latest ed21b7a8aee9 2 weeks ago 127MB
mysql latest 9228ee8bac7a 2 weeks ago 547MB
centos latest 470671670cac 2 months ago 237MB
操作系统组成部分:
- 进度调度子系统
- 进程通信子系统
- 内存管理子系统
- 设备管理子系统
- 文件管理子系统
- 网络通信子系统
- 作业控制子系统
linux文件系统由bootfs和rootfs两部分组成 - bootfs:包含bootloader(引导加载程序)和kernel(内核)
- rootfs:root文件系统,包含的就是典型linux系统中的/dev,/proc,/bin,/etc等标准目录和文件
- 不同的linux发行版,bootfs基本一样,而rootfs不同,如ubuntu,centos等
Docker镜像原理
- docker镜像是由特殊的文件系统叠加而成
- 最底端是bootfs,并使用宿主机的bootfs
- 第二层是root文件系统rootfs,称为base image,如centos,ubuntu等
- 再往上可以叠加其他的镜像文件
- 统一文件系统(Union File System)技术能够将不同的层整合成一个文件系统,为这些层提供了一个统一的视角,这样就隐藏了多层的存在,在用户角度看来,只存在一个文件系统。
- 一个镜像可以放在另一个镜像的上面,位于下面的镜像为父镜像,最底层的镜像称为基础镜像。
- 当从一个镜像启动容器时,docker会在最顶层加载一个读写文件系统作为容器
[root@docker ~]# docker inspect tomcat
[
{
"Id": "sha256:6ab907c973d29d79bd572c36e24d98e02f9774d567e081dad3ae5671ff5aff4f",
"RepoTags": [
"tomcat:latest"
],
"RepoDigests": [
"tomcat@sha256:89d20858a7a6696b7d5f728cb4283106b867abe7b8579d80c0b4715af9a580ac"
],
"Parent": "",
"Comment": "",
"Created": "2020-04-09T23:42:11.426401689Z",
"Container": "ddee0ab43c439125cfb6cbc72641b9560452984ab03bc0a4b4756245626ea0f8",
"ContainerConfig": {
"Hostname": "ddee0ab43c43",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/tomcat/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"JAVA_HOME=/usr/local/openjdk-8",
"JAVA_VERSION=8u242",
"JAVA_BASE_URL=https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_",
"JAVA_URL_VERSION=8u242b08",
"CATALINA_HOME=/usr/local/tomcat",
"TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib",
"LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib",
"GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23",
"TOMCAT_MAJOR=8",
"TOMCAT_VERSION=8.5.54",
"TOMCAT_SHA512=dc3ba0183d1e6f6006e5430e91abbc0758bdb719efebea5809f7034c9a28c590a764d8fcf2528a27a98cb86531e94cd9dc5a92cdbcae36e808ced0e5f1c665b8"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"catalina.sh\" \"run\"]"
],
"ArgsEscaped": true,
"Image": "sha256:62fc4c1271b212ca56827fe5c39cf85d5a052e4f5a5346c3f5d769beff94835e",
"Volumes": null,
"WorkingDir": "/usr/local/tomcat",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "18.09.7",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/tomcat/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"LANG=C.UTF-8",
"JAVA_HOME=/usr/local/openjdk-8",
"JAVA_VERSION=8u242",
"JAVA_BASE_URL=https://github.com/AdoptOpenJDK/openjdk8-upstream-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_",
"JAVA_URL_VERSION=8u242b08",
"CATALINA_HOME=/usr/local/tomcat",
"TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib",
"LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib",
"GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23",
"TOMCAT_MAJOR=8",
"TOMCAT_VERSION=8.5.54",
"TOMCAT_SHA512=dc3ba0183d1e6f6006e5430e91abbc0758bdb719efebea5809f7034c9a28c590a764d8fcf2528a27a98cb86531e94cd9dc5a92cdbcae36e808ced0e5f1c665b8"
],
"Cmd": [
"catalina.sh",
"run"
],
"ArgsEscaped": true,
"Image": "sha256:62fc4c1271b212ca56827fe5c39cf85d5a052e4f5a5346c3f5d769beff94835e",
"Volumes": null,
"WorkingDir": "/usr/local/tomcat",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 528486403,
"VirtualSize": 528486403,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/f74736e73e154f500b7362913aef4f058e518da52a7fa9dbcad4541a0f0b0543/diff:/var/lib/docker/overlay2/ca8d2f7e83a3a10b0b5abd3c8ccac6cb9ea48668836eb2a8ef05968af14c048e/diff:/var/lib/docker/overlay2/d0381dbf72074ca724c83dd80abcd76a817b4c2ac17268f8df5515dc7d440eb5/diff:/var/lib/docker/overlay2/c92f3aa6eb17f9edc09809acfe18b23984fd4e25f4ff0db9643f0d24a63d2a04/diff:/var/lib/docker/overlay2/73b158099e3348da265b10703974f4e9a235d0605b79bf5279e1fe676ba3131b/diff:/var/lib/docker/overlay2/a79936eceec831fe37dd757e355ffd77682272b03882e40ccf4c3a6ad6f067a9/diff:/var/lib/docker/overlay2/9bf7da5ac45b7be056dea38055101251cd6927cc1ca178490335747a6efb6f45/diff:/var/lib/docker/overlay2/d9419081a95f0f7b18632cae9151a1df2cc4da6a34c5dffe88c78384c49b5a3b/diff:/var/lib/docker/overlay2/75d002d5b8174ecb7e6f93d6823f09ef84a606bd48b870e326a1ff106474b2f8/diff",
"MergedDir": "/var/lib/docker/overlay2/802070d76744320bdb80a61a57818611cc3b352f2ad8bac8517b2c29ec71c908/merged",
"UpperDir": "/var/lib/docker/overlay2/802070d76744320bdb80a61a57818611cc3b352f2ad8bac8517b2c29ec71c908/diff",
"WorkDir": "/var/lib/docker/overlay2/802070d76744320bdb80a61a57818611cc3b352f2ad8bac8517b2c29ec71c908/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:24efcd549ab5e1786f787e7dc03590dcb222e7e95242524d97fedeb05393e891",
"sha256:185574602537cace768b9d1f17be24b5f6ba98f856a7e47a2c79ba757de9df4f",
"sha256:136a15f81f257d3851700658c368a93eecda01b39bbdaa52670ee6cd4816caae",
"sha256:afae6f50abb9a0a8ff88704e53551b4b14ef0432e860bfc78730a480dca020fb",
"sha256:23f8d486123a0b5d1e6e650407798a629ce92ff9bf019bf8b11eea5dcb0ef191",
"sha256:e811ee12aa100c16a1516b10a5f8c9e404727c54a30cbf7113ff7404f3b2059f",
"sha256:892007193bb6c3624120ac0b200888e8f05f858e5811bcd709c83f8983680680",
"sha256:81349fc07565090478202d6157d50787af22ec40d8daa456baa3706f0e6002b6",
"sha256:87af559013607d8fde58295a09458022aa6ba9308f5b329165348661e90a8e24",
"sha256:fb8f657b05a72af04f7daff7477b69d73e8295f010140334bab60cfdfdb2c0f0"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
可以看到tomcat的分层结构:
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:24efcd549ab5e1786f787e7dc03590dcb222e7e95242524d97fedeb05393e891",
"sha256:185574602537cace768b9d1f17be24b5f6ba98f856a7e47a2c79ba757de9df4f",
"sha256:136a15f81f257d3851700658c368a93eecda01b39bbdaa52670ee6cd4816caae",
"sha256:afae6f50abb9a0a8ff88704e53551b4b14ef0432e860bfc78730a480dca020fb",
"sha256:23f8d486123a0b5d1e6e650407798a629ce92ff9bf019bf8b11eea5dcb0ef191",
"sha256:e811ee12aa100c16a1516b10a5f8c9e404727c54a30cbf7113ff7404f3b2059f",
"sha256:892007193bb6c3624120ac0b200888e8f05f858e5811bcd709c83f8983680680",
"sha256:81349fc07565090478202d6157d50787af22ec40d8daa456baa3706f0e6002b6",
"sha256:87af559013607d8fde58295a09458022aa6ba9308f5b329165348661e90a8e24",
"sha256:fb8f657b05a72af04f7daff7477b69d73e8295f010140334bab60cfdfdb2c0f0"
]
},
2.2 镜像制作
2.2.1 容器转为镜像
1、commit制作镜像
[root@docker ~]# docker commit 9c946a828a7b new_tomcat:v1.0
sha256:5b82f557292f10a6a272fc9801a617275a8160309907912ae126612f1e66e1db
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
new_tomcat v1.0 5b82f557292f 5 seconds ago 529MB
tomcat latest 6ab907c973d2 6 days ago 528MB
redis latest 4cdbec704e47 2 weeks ago 98.2MB
nginx latest ed21b7a8aee9 2 weeks ago 127MB
mysql latest 9228ee8bac7a 2 weeks ago 547MB
centos latest 470671670cac 2 months ago 237MB
2、save压缩镜像文件
[root@docker ~]# docker save -o new_tomcat.tar new_tomcat:v1.0
[root@docker ~]#
可以看到已经在root目录下生成new_tomcat.tar压缩包文件
[root@docker ~]# ll
total 528128
-rw-------. 1 root root 1597 Mar 19 17:32 anaconda-ks.cfg
drwxr-xr-x. 2 root root 22 Apr 16 18:57 data
drwxr-xr-x. 2 root root 6 Apr 16 19:09 data2
drwxr-xr-x. 2 root root 6 Apr 16 19:09 data3
drwxr-xr-x. 5 root root 42 Apr 16 19:53 mysql
-rw-------. 1 root root 540798976 Apr 16 22:21 new_tomcat.tar
drwxr-xr-x. 5 root root 42 Apr 16 21:22 nginx
drwxr-xr-x. 3 root root 18 Apr 16 20:38 tomcat
[root@docker ~]#
3、load压缩文件生成镜像文件
由于我是在同一台机器上操作,所以先做下rmi镜像操作,再重新生成新的镜像文件
[root@docker ~]# docker rmi new_tomcat:v1.0
Untagged: new_tomcat:v1.0
Deleted: sha256:5b82f557292f10a6a272fc9801a617275a8160309907912ae126612f1e66e1db
Deleted: sha256:77f4e32b5029c6d491f4bc6c56a6e352d4defbff38fbca5b1ff424db7ffa5cb8
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest 6ab907c973d2 6 days ago 528MB
redis latest 4cdbec704e47 2 weeks ago 98.2MB
nginx latest ed21b7a8aee9 2 weeks ago 127MB
mysql latest 9228ee8bac7a 2 weeks ago 547MB
centos latest 470671670cac 2 months ago
[root@docker ~]# docker load -i new_tomcat.tar
80286702b0e2: Loading layer 50.18kB/50.18kB
Loaded image: new_tomcat:v1.0
[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
new_tomcat v1.0 5b82f557292f 7 minutes ago 529MB
tomcat latest 6ab907c973d2 6 days ago 528MB
redis latest 4cdbec704e47 2 weeks ago 98.2MB
nginx latest ed21b7a8aee9 2 weeks ago 127MB
mysql latest 9228ee8bac7a 2 weeks ago 547MB
centos latest 470671670cac 2 months ago 237MB
可以看到new_tomcat已经重新生成
4、根据新的镜像文件创建和运行容器
[root@docker ~]# docker run -it --name=c_new_tomcat new_tomcat:v1.0 bash
root@a1dac0360f44:/usr/local/tomcat# cd webapps
root@a1dac0360f44:/usr/local/tomcat/webapps# ls
root@a1dac0360f44:/usr/local/tomcat/webapps#
我们可以看到之前webapp中的test文件夹没有了,这说明通过commit创建的镜像是没有把数据卷共享过来。
2.2.2 dockfile制作镜像
dockerfile概念
- dockerfile是一个文本文件
- 包含了一条条的指令
- 每一条指令构建一层,基于基础镜像,最终构建出一个新的镜像
- 对于开发人员:可以为开发团队提供一个完全一致的开发环境
- 对于测试人员:可以直接拿开发所构建的镜像或者通过dockefile文件构建一个新的镜像开始工作了
- 对于运维人员:再部署时,可以实现应用的无缝移植
dockfile关键字介绍
关键字 | 作用 | 备注 |
---|---|---|
FROM | 指定父镜像 | 指定dockerfile基于哪个image构建 |
MAINTAINER | 作者信息 | 用来标明这个dockerfile谁写的 |
LABEL | 标签 | 用来标明dockerfile的标签,可以使用label代替Maintainer,最终都是再dockers image基本信息中可以查看 |
RUN | 执行命令 | 执行一段命令,默认时/bin/sh,格式:RUN command或者RUN [“command”,“param1”,“param2”] |
CMD | 容器启动命令 | 提供启动容器时候的默认命令和ENTRYPOINT配合使用,格式CMD command param1 param2或者CMD [“command”,“param1”,“param2”] |
ENTRYPOINT | 入口 | 一般再制作一些执行就关闭的容器中会使用 |
COPY | 复制文件 | build的时候复制文件到image中 |
ADD | 添加文件 | build的时候添加文件到image中,不仅仅局限于当前build上下文,可以来源于远程服务 |
ENV | 环境变量 | 指定build时候的环境变量,看可以在启动容器的时候,通过-e覆盖,格式ENV name=value |
ARG | 构建参数 | 构建参数,只在构建的时候使用的参数,如果由ENV,那么ENV的相同名字的值始终覆盖arg的参数 |
VOLUME | 定义外部可以挂载的数据卷 | 指定build的image那些目录可以启动的时候挂载到文件系统中,启动容器的时候使用-v绑定,格式volume[“path”] |
EXPOSE | 暴露端口 | 定义容器运行的时候监听的端口,启动容器时使用-p来绑定暴漏端口,格式:EXPOSE 8080或者EXPOSE 8080/udp |
WORKDIR | 工作目录 | 指定容器内部的工作目录,如果没有创建则自动创建,如果指定/使用的是绝对地址,如果不是/开头那么是在上一条workdir的路径的相对路径 |
USER | 指定执行用户 | 指定build或者启动的时候,用户在RUN CMD ENTRYPOINT执行的时候的用户 |
HEALTHCHECK | 健康检查 | 指定监测当前容器的健康监测的命令,基本上没用,因为很多时候,应用本身有健康监测机制 |
ONBUILD | 触发器 | 当存在ONBUILD关键字的镜像作为基础镜像的时候,当执行FROM完成之后会执行ONBUILD的命令,但是不影响当前镜像,用处也不怎么大 |
STOPSIGNAL | 发送信号量到宿主机 | 该STOPSIGNAL指令设置将发送到容器的系统调用信号以退出 |
SHELL | 指定执行脚本的shell | 指定RUN CMD ENTRYPOINT执行命令的时候,使用的shell |
案例一
自定义centos镜像。要求:
1、默认登陆路径为/usr
2、可以使用vim
先用正常docker run启动一个centos容器,我们发现,默认登陆路径为/,而且vim不能用
[root@docker ~]# docker run -it --name=c4 centos
[root@2c86fad4fdf2 /]# ll
bash: ll: command not found
[root@2c86fad4fdf2 /]# vim a.txt
bash: vim: command not found
[root@2c86fad4fdf2 /]#
首先我们按照需求先配置dockerfile文件
[root@docker ~]# mkdir docker-files
[root@docker ~]# cd docker-files/
[root@docker docker-files]# vim centos_dockfile
[root@docker docker-files]# ls
centos_dockfile
[root@docker docker-files]# cat centos_dockfile
FROM centos:latest
MAINTAINER davie67 <davie67@163.com>
RUN yum install -y vim
WORKDIR /usr
CMD ["/bin/bash"]
然后通过build命令制作镜像
[root@docker docker-files]# docker build -f ./centos_dockfile -t c5:v1.0 .
Sending build context to Docker daemon 2.048kB
Step 1/5 : FROM centos:latest
---> 470671670cac
Step 2/5 : MAINTAINER davie67 <davie67@163.com>
---> Running in 3fec5f316aaa
Removing intermediate container 3fec5f316aaa
---> 3394d87c4a60
Step 3/5 : RUN yum install -y vim
---> Running in 7ce0df844ee3
CentOS-8 - AppStream 1.1 MB/s | 6.8 MB 00:06
CentOS-8 - Base 1.1 MB/s | 6.0 MB 00:05
CentOS-8 - Extras 2.6 kB/s | 5.5 kB 00:02
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
vim-enhanced x86_64 2:8.0.1763-13.el8 AppStream 1.4 M
Installing dependencies:
gpm-libs x86_64 1.20.7-15.el8 AppStream 39 k
vim-common x86_64 2:8.0.1763-13.el8 AppStream 6.3 M
vim-filesystem noarch 2:8.0.1763-13.el8 AppStream 48 k
which x86_64 2.21-10.el8 BaseOS 49 k
Transaction Summary
================================================================================
Install 5 Packages
Total download size: 7.8 M
Installed size: 31 M
Downloading Packages:
(1/5): gpm-libs-1.20.7-15.el8.x86_64.rpm 83 kB/s | 39 kB 00:00
(2/5): vim-filesystem-8.0.1763-13.el8.noarch.rp 284 kB/s | 48 kB 00:00
(3/5): which-2.21-10.el8.x86_64.rpm 124 kB/s | 49 kB 00:00
(4/5): vim-enhanced-8.0.1763-13.el8.x86_64.rpm 918 kB/s | 1.4 MB 00:01
(5/5): vim-common-8.0.1763-13.el8.x86_64.rpm 642 kB/s | 6.3 MB 00:10
--------------------------------------------------------------------------------
Total 654 kB/s | 7.8 MB 00:12
warning: /var/cache/dnf/AppStream-02e86d1c976ab532/packages/gpm-libs-1.20.7-15.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - AppStream 1.4 MB/s | 1.6 kB 00:00
Importing GPG key 0x8483C65D:
Userid : "CentOS (CentOS Official Signing Key) <security@centos.org>"
Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : which-2.21-10.el8.x86_64 1/5
Installing : vim-filesystem-2:8.0.1763-13.el8.noarch 2/5
Installing : vim-common-2:8.0.1763-13.el8.x86_64 3/5
Installing : gpm-libs-1.20.7-15.el8.x86_64 4/5
Running scriptlet: gpm-libs-1.20.7-15.el8.x86_64 4/5
Installing : vim-enhanced-2:8.0.1763-13.el8.x86_64 5/5
Running scriptlet: vim-enhanced-2:8.0.1763-13.el8.x86_64 5/5
Running scriptlet: vim-common-2:8.0.1763-13.el8.x86_64 5/5
Verifying : gpm-libs-1.20.7-15.el8.x86_64 1/5
Verifying : vim-common-2:8.0.1763-13.el8.x86_64 2/5
Verifying : vim-enhanced-2:8.0.1763-13.el8.x86_64 3/5
Verifying : vim-filesystem-2:8.0.1763-13.el8.noarch 4/5
Verifying : which-2.21-10.el8.x86_64 5/5
Installed:
vim-enhanced-2:8.0.1763-13.el8.x86_64 gpm-libs-1.20.7-15.el8.x86_64
vim-common-2:8.0.1763-13.el8.x86_64 vim-filesystem-2:8.0.1763-13.el8.noarch
which-2.21-10.el8.x86_64
Complete!
Removing intermediate container 7ce0df844ee3
---> d78ce19bcac5
Step 4/5 : WORKDIR /usr
---> Running in ebe839997d2b
Removing intermediate container ebe839997d2b
---> e13ec1dd7ad8
Step 5/5 : CMD ["/bin/bash"]
---> Running in 9ea8e43779fe
Removing intermediate container 9ea8e43779fe
---> be275286a1dc
Successfully built be275286a1dc
Successfully tagged c5:v1.0
可以看到image已经创建好了
[root@docker docker-files]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
c5 v1.0 be275286a1dc 2 minutes ago 302MB
new_tomcat v1.0 5b82f557292f 57 minutes ago 529MB
tomcat latest 6ab907c973d2 6 days ago 528MB
redis latest 4cdbec704e47 2 weeks ago 98.2MB
nginx latest ed21b7a8aee9 2 weeks ago 127MB
mysql latest 9228ee8bac7a 2 weeks ago 547MB
centos latest 470671670cac 2 months ago 237MB
我们根据c5的镜像模板来创建并进入容器里验证下
[root@docker docker-files]# docker run -it --name=c5 c5:v1.0
[root@ac8c392af32d usr]# vim test.txt
[root@ac8c392af32d usr]#
工作路径默认变成了/usr,而且vim也没有报错
案例二
发布hello.py的脚本文件
hello.py的脚本文件比较简单
print('hello container')
这里我们重点配置下dockerfile文件,注意py文件和dockerfile文件在一个目录下,如果在不同目录,要把dockerfile的文件路径写全
[root@docker docker-files]# cat hello_dockfile
FROM python:3.8
MAINTAINER davie67 <davie67@163.com>
ADD hello.py hello.py
CMD python3 hello.py
build生成一个镜像文件
[root@docker docker-files]# docker build -f ./hello_dockfile -t hello:v1.0 .
Sending build context to Docker daemon 4.096kB
Step 1/4 : FROM python:3.8
3.8: Pulling from library/python
f15005b0235f: Already exists
41ebfd3d2fd0: Already exists
b998346ba308: Already exists
f01ec562c947: Already exists
2447a2c11907: Pull complete
fdd2d569da3e: Pull complete
ac3886b74a9f: Pull complete
3c783a9b35dd: Pull complete
ce16dda809f6: Pull complete
Digest: sha256:7a50a637fc3b6b0f66297bc2003af6c19f4acffcde771a3dd92712ec8bad7117
Status: Downloaded newer image for python:3.8
---> d47898c6f4b0
Step 2/4 : MAINTAINER davie67 <davie67@163.com>
---> Running in 67fa111d9d71
Removing intermediate container 67fa111d9d71
---> 738abba8d4ea
Step 3/4 : ADD hello.py hello.py
---> c02b895ff626
Step 4/4 : CMD python3 hello.py
---> Running in 87f8651a433f
Removing intermediate container 87f8651a433f
---> 1eee8113dc65
Successfully built 1eee8113dc65
Successfully tagged hello:v1.0
如果宿主机没有python3.8,dockerfile会自动下载。
[root@docker docker-files]# docker images
REPOSITORY TAG IMAGE ID CREATED
hello v1.0 1eee8113dc65 10 seconds ago
new_tomcat v1.0 5b82f557292f 2 hours ago
tomcat latest 6ab907c973d2 6 days ago
python 3.8 d47898c6f4b0 2 weeks ago
redis latest 4cdbec704e47 2 weeks ago
nginx latest ed21b7a8aee9 2 weeks ago
mysql latest 9228ee8bac7a 2 weeks ago
centos latest 470671670cac 2 months ago
我们看到hello的镜像文件已经创建好了
我们再根据hello镜像文件创建和启动容器
[root@docker docker-files]# docker run -it --name=hello hello:v1.0
hello container
测试ok