设为首页 收藏本站
查看: 800|回复: 0

[经验分享] Docker(2)Repositories and PHP example on CentOS

[复制链接]

尚未签到

发表于 2016-1-11 13:54:47 | 显示全部楼层 |阅读模式
Docker(2)Repositories and PHP example on CentOS

1. Repositories
for example, dl.dockerpool.com/ubuntu, dl.dockerpool.com is a registry server, ubuntu is the repository name.

Here is my private repo
https://registry.hub.docker.com/u/sillycat/machinelearning/

Here is my public repo
https://registry.hub.docker.com/u/sillycat/public/

Login the docker hub
> sudo docker login
Username: sillycat
Password:
Email: luohuazju@gmail.com
Login Succeeded

The information will be stored here
> sudo vi ~/.dockercfg

Build the image
> sudo docker build -t="sillycat/public" .

List the info
> sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED              VIRTUAL SIZE
sillycat/public     latest              8800fd804e5c        About a minute ago   301 MB

This will push the images to my repo
> sudo docker push sillycat/public

Pull the images
> sudo docker pull sillycat/public

For private repo with tag
> sudo docker build -t="sillycat/machinelearning:v1.0" .
> sudo docker push sillycat/machinelearning
> sudo docker pull sillycat/machinelearning:v1.0

2. Example to Build PHP Env on CentOS
Pull the images
> sudo docker pull centos

Start the container for trying purpose
> sudo docker run -t -i centos:7 /bin/bash

Build the Image for PHP
> sudo docker build -t sillycat/public:centos7-php .

Remove the images with their IMAGE ID
> sudo docker rmi -f 70f8f9ad6d7f

List the current running containers
> sudo docker ps

Stop the container by their names
> sudo docker stop grave_morse

Check the IP address for a container
> sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' centos7-php

Inspect all the data for one container
> sudo docker inspect centos7-nginx

Introduce some key things in sillycat-docker project
for centos7-php
We have a docker file Dockerfile, the content will be something like this:
FROM        centos:7      

#PHP 5.6.10 and PHP-FPM
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
RUN rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

RUN yum install -y php56w php56w-fpm
RUN yum install -y telnet

# Add in the php fpm configuration
ADD        www.conf /etc/php-fpm.d/

#Prepare the Content
RUN        mkdir -p /app/htdocs
ADD        htdocs/ /app/htdocs/
#VOLUME        /app/htdocs

#Prepare the shell
ADD        start.sh /app/

#excute the shell
CMD        /app/start.sh

This will prepare the system, pre-install a lot of software for me and copy the binary to work directory and start the application at last.

The start.sh will be just simple command to start the php-fpm
#!/bin/sh -ex

php-fpm --nodaemonize

The most import part to make www.conf work for php-fpm is the listen configuration
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen=9000

It will listen to all the client IP addresses.

Under the htdocs/index.php, it is just a really simple hello word.
<?php
echo "Hello, sillycat!\n\n\n";
phpinfo();
?>

And the Makefile Command file really help me, it is hard to remember all the options and command in docker,
IMAGE=sillycat/public
TAG=centos7-php
NAME=centos7-php

docker-context:

build: docker-context
    sudo docker build -t $(IMAGE):$(TAG) .

run:
    sudo docker run -d --name $(NAME) $(IMAGE):$(TAG)

run-volume:
    sudo docker run -d --name $(NAME) -v $(shell pwd)/htdocs:/app/htdocs:ro $(IMAGE):$(TAG)
#    docker run -ti --name $(NAME) -v $(shell pwd)/htdocs:/app/htdocs:ro $(IMAGE):$(TAG) /bin/bash

debug:
    sudo docker run -ti --name $(NAME) $(IMAGE):$(TAG) /bin/bash

clean:
    sudo docker stop ${NAME}
    sudo docker rm ${NAME}

logs:
    sudo docker logs ${NAME}

publish:
    sudo docker push ${IMAGE}

These command will do the build, run, debug and clean publish.
> make build
> make publish

Little new things for nginx to running on docker
php-fpm.conf
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /app/htdocs;
        fastcgi_pass   centos7-php:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

Dockerfile
#fetch and pick the OS first
FROM    centos:7

#Install nginx
RUN yum install -y epel-release
RUN yum install -y nginx
RUN yum install -y telnet

EXPOSE  80
ADD     php-fpm.conf /etc/nginx/default.d/

RUN     mkdir -p /app/
ADD     start.sh /app/

CMD    /app/start.sh

Then we can visit this page URLs to verify
http://ubuntu-pilot:8080/index.php
http://ubuntu-pilot:8080

May read more things on VOLUME and WORKDIR in the future.
Compile and Run on Dockerfile is working as well.
#fetch and pick the OS first
FROMcentos:7

#prepare build env
RUN     yum install -y wget gcc make

#prepare libraries for nginx
RUN     yum install -y zlib-devel pcre-devel

#download resource and build and install nginx
RUN     mkdir  /install/
WORKDIR /install/

RUN     wget http://nginx.org/download/nginx-1.9.2.tar.gz
RUN     tar zxvf nginx-1.9.2.tar.gz
WORKDIR /install/nginx-1.9.2
RUN     ./configure --prefix=/tool/nginx-1.9.2
RUN     make && make install

EXPOSE  80
ADD     nginx.conf /tool/nginx-1.9.2/conf/

RUN     mkdir -p /app/
ADD     start.sh /app/

CMD/app/start.sh

References:
http://sillycat.iyunv.com/blog/2223733
http://dockerpool.com/static/books/docker_practice/repository/README.html

http://blog.arungupta.me/pushing-docker-images-registry-techtip58/

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-163105-1-1.html 上篇帖子: CentOS7中Docker文件挂载,容器中的权限问题 下篇帖子: 【转】唱衰docker,给大红大火的Docker泼点冷水
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表