赞
踩
本次实战是对着网易云课堂的免费课程操作记录。有兴趣的童鞋可以直接去看视频docker实战之路
git clone https://gitee.com/byleila/docker-training.git
使用现有的dockerfile创建一个镜像
语法:docker build -t registry_url/namespace/镜像名称:镜像版本 /dockerfile path
docker build -t csphere/centos:7.1 .
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
csphere/centos 7.1 a21878377f20 21 seconds ago 612.9 MB
docker.io/centos centos7.1.1503 fbe8925ecf55 12 weeks ago 212.1 MB
# docker help run
# docker run -d -p 2222:22 --name base csphere/centos:7.1
3a1459de687c89067a4b638ae7007538dfbc5f3590c04c7424c6ac4b4c1ded54
参数说明:
-d : 后台运行容器,返回容器id
-p : 设定指定端口映射
--name : 容器名称
最后指定使用的镜像REPOSITORY:TAG
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a1459de687c csphere/centos:7.1 "/usr/bin/supervisord" 12 minutes ago Up 12 minutes 0.0.0.0:2222->22/tcp base
docker ps -a 查看所有容器
# docker build -t csphere/php-fpm:5.4 .
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
csphere/centos 7.1 a21878377f20 3 hours ago 612.9 MB
csphere/php-fpm 5.4 a21878377f20 3 hours ago 612.9 MB
# docker run -d -p 8080:80 --name website csphere/php-fpm:5.4
f1a34ae0d90da8513c81b24298e8c22b60d557f11c2b2f56a0500f042a0aa01f
[root@localhost centos7]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f1a34ae0d90d csphere/php-fpm:5.4 "/usr/bin/supervisord" 8 seconds ago Up 6 seconds 22/tcp, 0.0.0.0:8080->80/tcp website
3a1459de687c csphere/centos:7.1 "/usr/bin/supervisord" 50 minutes ago Up 50 minutes 0.0.0.0:2222->22/tcp base
在浏览器中访问:http://ip:8080/info.php,可以查看到“
PHP Logo
PHP Version 5.4.16”的说明,说明php启动成功。
查看docker中的应用是否启动:
#进入容器
[root@localhost php-fpm]# docker exec -it website /bin/bash
[root@7c7382fed9a1 /]# supervisorctl
nginx RUNNING pid 7, uptime 0:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。