参考文章
http://www.php.cn/php-weizijiaocheng-387055.html
https://blog.csdn.net/abld99/article/details/68486517
https://blog.csdn.net/z_qifa/article/details/74202882
本次目标制作一个lnmp环境的镜像
1、下载centos镜像
docker pull centos:latest //默认下载最新 本次下载7.4版本
2、由centos镜像启动一个容器
docker run -it centos /bin/bash
容器和镜像的关系可以理解为: 面向对象编程中类和实例的关系
3、安装php
1、更改yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2、安装php
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml php72w-pecl-redis php72w-pecl-memcached
3、检查php是否安装成功
php -v
4、安装nginx
yum install nginx -y
5、安装mysql
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install -y mysql-server
//安装成功后
exit //退出容器
5、提交镜像(将容器提交成镜像)
docker commit {containerid} {containername}:{version}
查看刚刚制作的镜像
[root@instance-5hox4i4w ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xc1992/linux_mysql_php latest e5c29de6809a 2 hours ago 1.27GB
centos latest 9f38484d220f 4 months ago 202MB
web_php_nginx latest d70d8e3c5ef5 8 months ago 497MB
dhshen/php_env latest de9c6e192460 8 months ago 487MB
centos <none> 75835a67d134 10 months ago 200MB
hello-world latest 4ab4c602aa5e 11 months ago 1.84kB
ubuntu 15.10 9b9cb95443b5 3 years ago 137MB
6、用刚创建的镜像运行容器
创建容器 并 挂载到主机指定节点
docker run --privileged -it -p 80:80 -v /www:/www -d dhshen/php_env /usr/sbin/init //必须执行这个命令 否则无法使用systemctl命令
容器的 /www 目录会挂载到主机的 /www 下 这时只需要将应用代码放在宿主主机的/www 目录 容器即可访问到
7、上传镜像
[root@instance-5hox4i4w ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: xc1992
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@instance-5hox4i4w ~]# docker push xc1992/linux_mysql_php
The push refers to repository [docker.io/xc1992/linux_mysql_php]
189e000f8ba4: Pushing [===> ] 80.29MB/1.064GB
189e000f8ba4: Pushing [==========================================> ] 912.4MB/1.064GB
接下来耐心等待即可,上传完成后查看地址 https://hub.docker.com/r/inteye/lnmp/tags