`
sillycat
  • 浏览: 2551295 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Docker(2)Repositories and PHP example on CentOS

 
阅读更多
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
FROM centos: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.iteye.com/blog/2223733
http://dockerpool.com/static/books/docker_practice/repository/README.html

http://blog.arungupta.me/pushing-docker-images-registry-techtip58/
分享到:
评论

相关推荐

    centos7.6离线安装docker-ce-19.03、nvidia-docker2

    离线环境下,在centos7.6系统上安装docker-ce-19.03,nvidia-docker2.4版本,其中docker-ce-19.03在docker-local.tar压缩文件里面,nvidia-docker2在nvidia-docker2.zip文件中。 具体安装流程如下: 1.安装docker ...

    centos7.6机器上离线安装docker-ce-19.03、nvidia-docker2

    在CentOS 7.6上离线安装Docker CE 19.03和Nvidia Docker 2可以按照以下步骤进行操作: 首先,您需要从Docker官方网站或Nvidia Docker官方网站下载对应版本的安装包。确保选择与您的操作系统和架构(例如x86_64)...

    docker-ce-20.10.12 centos7.x 离线安装含依赖包

    2. **上传到服务器**:将包含所有RPM包的压缩文件上传到你的CentOS 7服务器。可以使用FTP、SCP或其他文件传输工具完成这个步骤。 3. **解压并安装**:在服务器上找到你的压缩包位置,使用`unzip`或`tar`命令解压。...

    【docker-centos7】docker在centos7中如何安装??.md【docker-centos7】docker在c

    【docker_centos7】docker在centos7中如何安装??.md【docker_centos7】docker在centos7中如何安装??.md【docker_centos7】docker在centos7中如何安装??.md【docker_centos7】docker在centos7中如何安装??.md

    CentOS7_nvidia-docker2安装.rar

    centos7 nvidia-docker2离线安装包,使用命令rpm -ivh --force *.rpm sudo systemctl restart docker sudo systemctl daemon-reload 依次执行此命令,如果 事先安装了containerd.io 则需要先进行 rpm -qa | grep ...

    CentOS7 Docker Tar镜像

    CentOS7 Docker Tar镜像,

    centos6.8-离线安装docker环境所需的rpm

    在本文中,我们将深入探讨如何在CentOS 6.8系统上离线安装Docker环境,这主要依赖于RPM(Red Hat Package Manager)包。RPM是Linux发行版如CentOS用来安装、升级和管理软件的主要方式。由于是离线安装,我们需要预先...

    docker笔记、快速使用docker拉取centos

    使用Docker将镜像从一个主机迁移到另一个主机,可以使用以下命令:`docker save 镜像名 | bzip2 | ssh root@10.140.1.120 "cat | docker load"` 八、Docker解压镜像 使用Docker解压镜像可以使用以下命令:`docker ...

    centos 6.9安装docker步骤

    Centos 6.9安装docker步骤,同步部署。自己整理容器实用。

    docker、docker-compose一键安装,适配CentOS、银河麒麟、统信UOS等

    docker、docker_compose一键安装,适配CentOS、银河麒麟、统信UOS等。

    极空间docker搭建centos

    2. 使用 Docker 可以创建基于 CentOS 的镜像文件。 3. 配置基本设置和端口是搭建容器的重要步骤。 4. 安装必要的软件包是搭建容器的重要步骤。 5. 更新所有程序是搭建容器的重要步骤。 6. 使用 `sed` 命令可以更新...

    centos7.5docker镜像

    在基础镜像centos7.5的基础上,增加了vim,net-tools命令,及libnpg,gtk2系统库。

    CentOS7下Docker桥接网络配置

    ### CentOS7下Docker桥接网络配置详解 #### 一、背景介绍 Docker作为一种流行的容器化技术,为开发者提供了轻量级、可移植的容器环境。为了更好地管理容器之间的网络通信,理解Docker在网络配置方面的机制至关重要...

    centos下nvidia-docker2环境安装离线安装资料包

    本离线安装资料包提供了在CentOS上安装NVIDIA-Docker2的步骤,尤其适合网络环境不稳定或者需要离线安装的场景。 首先,你需要确保系统已经安装了Docker。在CentOS中,可以通过以下步骤安装: 1. 更新系统软件包: ...

    docker 24.06 centos7 离线安装包

    docker 24.06 centos7 离线安装包

    CentOS6.7 Docker最小版镜像

    CentOS6.7 Docker最小版镜像 最小版的CentOS6.7,安装了openssh、wget、vim、target,用户名:root/root

    CentOS7 Docker防火墙的简单配置教程

    CentOS7 Docker防火墙的简单配置 禁用 firewalld 服务 systemctl disable firewalld systemctl stop firewalld 安装 iptables 防火墙服务 yum install iptables-services 创建 iptables 配置脚本 cat &gt;&gt; /usr/...

    centos7 docker CE入门及安装

    这个我亲手写的docker入门教程,适合入门者,欢迎下载。

    arm架构centos7安装docker

    安装步骤参考:https://blog.csdn.net/chkai123/article/details/126229727 docker离线安装 arm架构下离线安装docker docker centos7离线安装docekr 离线安装docker arm架构下安装docker arm架构centos7安装docker

    Docker 安装 Oracle11g(CentOs).pdf

    Docker 安装 Oracle11g(CentOs)

Global site tag (gtag.js) - Google Analytics