自定义创建Docker镜像,上传至Docker Hub并使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义创建Docker镜像,上传至Docker Hub并使用相关的知识,希望对你有一定的参考价值。

自定义创建Docker镜像

选择基础镜像系统

docker pull centos:7

确定镜像的功能

基于选择的基础镜像创建容器

docker run -itd --name ganglia --privileged=true centos:7

Ganglia概述

官网地址:http://ganglia.info/

核心组成

Ganglia由gmond、gmetad和ganglia-web三部分组成。

开始构建

docker exec -it ganglia  /bin/bash

安装httpd服务与php

yum -y install httpd php

安装其他依赖

yum -y install rrdtool perl-rrdtool rrdtool-devel
yum -y install apr-devel

安装ganglia

yum -y install ganglia-gmetad
yum -y install ganglia-web
yum install -y ganglia-gmond

配置

修改配置文件 vim /etc/httpd/conf.d/ganglia.conf

Alias /ganglia /usr/share/ganglia
<Location /ganglia>
  Order deny,allow
  Deny from all
  # Allow from 127.0.0.1
  # Allow from ::1
  # Allow from .example.com
</Location>

Alias /ganglia /usr/share/ganglia
<Location /ganglia>
  # Order deny,allow
  # Deny from all
  # Allow from 127.0.0.1
  # Allow from ::1
  Allow from all
  # Allow from .example.com
  
  Require all granted
</Location>

修改配置文件vim /etc/ganglia/gmetad.conf

data_source "my cluster" localhost(本机的ip地址)

修改配置文件vim /etc/ganglia/gmond.conf

cluster 
  name = "unspecified"
  owner = "unspecified"
  latlong = "unspecified"
  url = "unspecified"


cluster 
  name = "my_cluster"
  owner = "unspecified"
  latlong = "unspecified"
  url = "unspecified"

udp_send_channel 
  #bind_hostname = yes # Highly recommended, soon to be default.
                       # This option tells gmond to use a source address
                       # that resolves to the machines hostname.  Without
                       # this, the metrics may appear to come from any
                       # interface and the DNS names associated with
                       # those IPs will be used to create the RRDs.
  mcast_join = 239.2.11.71
  port = 8649
  ttl = 1


udp_send_channel 
  #bind_hostname = yes # Highly recommended, soon to be default.
                       # This option tells gmond to use a source address
                       # that resolves to the machines hostname.  Without
                       # this, the metrics may appear to come from any
                       # interface and the DNS names associated with
                       # those IPs will be used to create the RRDs.
  # mcast_join = 239.2.11.71
  host=127.0.0.1
  port = 8649
  ttl = 1

udp_recv_channel 
  mcast_join = 239.2.11.71
  port = 8649
  bind = 239.2.11.71
  retry_bind = true
  # Size of the UDP buffer. If you are handling lots of metrics you really
  # should bump it up to e.g. 10MB or even higher.
  # buffer = 10485760



udp_recv_channel 
  # mcast_join = 239.2.11.71
  port = 8649
  bind = 127.0.0.1
  retry_bind = true
  # Size of the UDP buffer. If you are handling lots of metrics you really
  # should bump it up to e.g. 10MB or even higher.
  # buffer = 10485760

修改配置文件vim /etc/selinux/config

SELINUX=disabled

启动相关服务

启动服务

systemctl httpd start
systemctl gmetad start
systemctl gmond start

设置开机启动

systemctl enable start
systemctl enable start
systemctl enable start

将容器提交为镜像

基于基础容器之上进行操作完成后,将其提交为新的镜像

docker commit ganglia  ganglia:latest

使用创建的镜像创建容器

docker run -itd --name ganglia -p 8080:80 -p 8081:8649  --privileged=true ganglia:latest

访问:IP:8080/ganglia

Docker Hub

注册账号

访问: https://hub.docker.com/注册账号

登录账号

命令行登录账号

docker login -u username

Tag镜像

新建一个tag,名字必须跟注册账号一样

docker tag test:v1 username/test:v1

推送

docker push username/test:v1

拉取

docker pull username/test:v1

部署

docker run -itd 8080:80 username/test:v1

以上是关于自定义创建Docker镜像,上传至Docker Hub并使用的主要内容,如果未能解决你的问题,请参考以下文章

Docker: 上传镜像至docker仓库或者阿里云仓库

Docker容器——将自定义容器上传到阿里云容器镜像服务中(三)

Docker自定义私有镜像仓库

将本地docker镜像上传至阿里云镜像仓库

Docker之Alpine制作镜像且上传至阿里云

docker基础——自定义镜像创建私有仓库查看 docker 运行状态