DockerfileHarbor镜像仓库

Posted linux985

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DockerfileHarbor镜像仓库相关的知识,希望对你有一定的参考价值。


一、Dockerfile

 


1.Dockerfile格式
2.Dockerfile指令
3.Build镜像
4.构建nginxphp,Tomcat基础镜像
5.快速搭建LNMP网站平台

 

 


1、Dockerfile格式

技术图片

 

 

 

 

2、Dockerfile指令


技术图片

 

 

 

 

[root@docker01 ~]# docker history nginx:1.15
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
53f3fd8007f7        12 months ago       /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B       #cmd命令           
<missing>           12 months ago       /bin/sh -c #(nop)  STOPSIGNAL SIGTERM           0B                  
<missing>           12 months ago       /bin/sh -c #(nop)  EXPOSE 80                    0B                   #EXPOSE 暴露端口
<missing>           12 months ago       /bin/sh -c ln -sf /dev/stdout /var/log/nginx…   22B                 
<missing>           12 months ago       /bin/sh -c set -x  && apt-get update  && apt…   54.1MB              
<missing>           12 months ago       /bin/sh -c #(nop)  ENV NJS_VERSION=1.15.12.0…   0B        #ENV 环境变量         
<missing>           12 months ago       /bin/sh -c #(nop)  ENV NGINX_VERSION=1.15.12…   0B                  
<missing>           12 months ago       /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B                  
<missing>           12 months ago       /bin/sh -c #(nop)  CMD ["bash"]                 0B                  #cmd命令
<missing>           12 months ago       /bin/sh -c #(nop) ADD file:fcb9328ea4c115670…   55.3MB              
[root@docker01 ~]# 

 


3、Build镜像

docker  build    -t  新构建镜像名称  -f 指定Dockerfile文件位置      其他配置文件路径
Usage: docker build [OPTIONS] PATH | URL | -[flags]Options:
-t, --tag list # 镜像名称
-f, --file string # 指定Dockerfile文件位置
# docker build .
# docker build -t shykes/myapp .
# docker build -t shykes/myapp -f /path/Dockerfile /path
# docker build -t shykes/myapp http://www.example.com/Dockerfile

 

[root@localhost ~]# vim dockerfile
FROM centos:7
MAINTAINER mxxl
RUN yum install httpd -y
COPY index.html /var/www/html
ENV HTTP_V=2.0
EXPOSE 80
WORKDIR /tmp
CMD ["httpd","-D","FOREGROUND"]
[root@localhost ~]# 
[root@localhost ~]# vim index.html
haha
[root@localhost ~]# docker build -t http:v2 .
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
http                             v2                  d45266d7ce19        4 minutes ago       298MB

[root@localhost ~]# docker inspect b3217f3dec25 |grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",
[root@localhost ~]# 
[root@localhost ~]# curl 172.17.0.2
haha
[root@localhost ~]# 

 





4、构建业务基础镜像
•构建Nginx基础镜像
•构建PHP基础镜像
•构建Tomcat基础镜像


快速部署LNMP网站平台
1、自定义网络
docker network create lnmp
2、创建mysql容器
docker run -d
--name lnmp_mysql
--net lnmp
--mount src=mysql-vol,dst=/var/lib/mysql
-e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress mysql:5.7 --character-set-server=utf8
3、创建PHP容器
docker run -d --name lnmp_php --net lnmp --mount src=wwwroot,dst=/wwwroot php:v1
4、创建Nginx容器
docker run -d --name lnmp_nginx --net lnmp -p 88:80
--mount type=bind,src=$(pwd)/nginx.conf,dst=/usr/local/nginx/conf/nginx.conf --mount src=wwwroot,dst=/wwwroot nginx:v1
5、以wordpress博客为例
https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz


1、自定义网络
[root@docker01 ~]# docker network create lnmp
9cdfea34f9cd55af4fca8e2bf3be6ca92cab1ca2632a5ec1178173420d52ccaf
[root@docker01 ~]#
[root@docker01 ~]# ls
anaconda-ks.cfg  dockerfile  wordpress-4.9.4-zh_CN.tar.gz
[root@docker01 ~]# cd dockerfile/
[root@docker01 dockerfile]# ls
Dockerfile-nginx  Dockerfile-php  Dockerfile-tomcat  nginx.conf  php-fpm.conf  php.ini
2、创建Mysql容器
[root@docker01 dockerfile]#
docker run -d
--name lnmp_mysql
--net lnmp
--mount src=mysql-vol,dst=/var/lib/mysql
-e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress mysql:5.7 --character-set-server=utf8
3、创建PHP容器
[root@localhost dockerfile]# cat Dockerfile-php #php镜像构造的dockerfile
FROM centos:7
MAINTAINER mxxl
RUN yum install epel-release -y &&
    yum install -y gcc gcc-c++ make gd-devel libxml2-devel
    libcurl-devel libjpeg-devel libpng-devel openssl-devel
    libmcrypt-devel libxslt-devel libtidy-devel autoconf
    iproute net-tools telnet wget curl &&
    yum clean all &&
    rm -rf /var/cache/yum/*

RUN wget http://docs.php.net/distributions/php-5.6.36.tar.gz &&
    tar zxf php-5.6.36.tar.gz &&
    cd php-5.6.36 &&
    ./configure --prefix=/usr/local/php
    --with-config-file-path=/usr/local/php/etc
    --enable-fpm --enable-opcache
    --with-mysql --with-mysqli --with-pdo-mysql
    --with-openssl --with-zlib --with-curl --with-gd
    --with-jpeg-dir --with-png-dir --with-freetype-dir
    --enable-mbstring --with-mcrypt --enable-hash &&
    make -j 4 && make install &&
    cp php.ini-production /usr/local/php/etc/php.ini &&
    cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf &&
    sed -i "90a daemonize = no" /usr/local/php/etc/php-fpm.conf &&
    mkdir /usr/local/php/log &&
    cd / && rm -rf php* &&
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/php/sbin
COPY php.ini /usr/local/php/etc/
COPY php-fpm.conf /usr/local/php/etc/
WORKDIR /usr/local/php
EXPOSE 9000
CMD ["php-fpm"]
[root@localhost dockerfile]#

[root@docker01 dockerfile]# docker build -t php:v1 -f Dockerfile-php .

[root@localhost dockerfile]# docker image ls
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
php                              v1                  2a2ced00c520        8 months ago        522MB
mysql                            5.7                 e1e1680ac726        8 months ago        373MB
centos                           7                   9f38484d220f        13 months ago       202MB
[root@localhost dockerfile]#

[root@localhost dockerfile]# docker run -d --name lnmp_php --net lnmp --mount src=wwwroot,dst=/wwwroot php:v1
daf78c56eef3ca34d6e1ae6f7078b1332d85e70c9f43abe29639910c72e5a3e9
[root@localhost dockerfile]#
[root@localhost dockerfile]# docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
daf78c56eef3        php:v1              "php-fpm"           17 seconds ago      Up 15 seconds       9000/tcp            lnmp_php
[root@localhost dockerfile]#

4、创建Nginx容器
[root@localhost dockerfile]# cat Dockerfile-nginx  #nginx镜像构造的dockerfile
FROM centos:7
MAINTAINER mxxl
RUN yum install -y gcc gcc-c++ make
    openssl-devel pcre-devel gd-devel
    iproute net-tools telnet wget curl &&
    yum clean all &&
    rm -rf /var/cache/yum/*
RUN wget http://nginx.org/download/nginx-1.15.5.tar.gz &&
    tar zxf nginx-1.15.5.tar.gz &&
    cd nginx-1.15.5 &&
    ./configure --prefix=/usr/local/nginx
    --with-http_ssl_module
    --with-http_stub_status_module &&
    make -j 4 && make install &&
    rm -rf /usr/local/nginx/html/* &&
    echo "ok" >> /usr/local/nginx/html/status.html &&
    cd / && rm -rf nginx-1.15.5* &&
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ENV PATH $PATH:/usr/local/nginx/sbin
COPY nginx.conf /usr/local/nginx/conf/nginx.conf
WORKDIR /usr/local/nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
[root@localhost dockerfile]#

[root@localhost dockerfile]# docker build -t nginx:v1 -f Dockerfile-nginx .

[root@localhost dockerfile]# docker run -d --name lnmp_nginx --net lnmp -p 88:80  --mount src=wwwroot,dst=/wwwroot nginx:v1
2dee39b481b205b8270624fe11e66008d6b68141c39f7f0f3af3612bd16e2716
[root@localhost dockerfile]#

5、以wordpress博客为例
https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
[root@localhost dockerfile]# tar -xf wordpress-4.9.4-zh_CN.tar.gz
[root@localhost dockerfile]# ls
[root@localhost dockerfile]# mv wordpress /var/lib/docker/volumes/wwwroot/_data/
[root@localhost dockerfile]#

[root@localhost mnt]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
2dee39b481b2        nginx:v1            "nginx -g ‘daemon of…"   4 minutes ago       Up 3 minutes        0.0.0.0:88->80/tcp    lnmp_nginx
daf78c56eef3        php:v1              "php-fpm"                9 minutes ago       Up 9 minutes        9000/tcp              lnmp_php
54d19fe86053        mysql:5.7           "docker-entrypoint.s…"   21 minutes ago      Up 21 minutes       3306/tcp, 33060/tcp   lnmp_mysql
[root@localhost mnt]#


以上是关于DockerfileHarbor镜像仓库的主要内容,如果未能解决你的问题,请参考以下文章

VIM 代码片段插件 ultisnips 使用教程

如何将git repo同步到镜像仓库

超详细入门精讲数据仓库原理&实战 一步一步搭建数据仓库 内附相应实验代码和镜像数据和脚本

Docker 镜像容器仓库三大基本概念

Docker私有仓库Registry的搭建验证

Docker安装私有仓库,用户认证(Registry)