docker镜像制作_03

一、docker镜像制作

1.1、获取centos镜像

docker pull centos

1.2、查看镜像

[root@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/nginx latest cd5239a0906a 10 days ago 109 MB
docker.io/centos latest 49f7960eb7e4 11 days ago 200 MB
docker.io/alpine latest 3fd9065eaf02 5 months ago 4.15 MB

1.3、进入容器安装wget

[root@docker ~]# docker run -it centos bash
[root@f8988cf8bfda /]# cd
[root@f8988cf8bfda ~]# ls
anaconda-ks.cfg

#进入yum源目录
[root@f8988cf8bfda ~]# cd /etc/yum.repos.d/
[root@f8988cf8bfda yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo

#安装wget
[root@f8988cf8bfda yum.repos.d]# yum install wget -y
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: mirrors.cqu.edu.cn
 * extras: mirrors.163.com
 * updates: free.nchc.org.tw
base                                                                        | 3.6 kB  00:00:00     
extras                                                                      | 3.4 kB  00:00:00     
updates                                                                     | 3.4 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                               | 166 kB  00:00:00     
(2/4): base/7/x86_64/primary_db                                             | 5.9 MB  00:00:02     
(3/4): updates/7/x86_64/primary_db                                          | 2.7 MB  00:00:05     
(4/4): extras/7/x86_64/primary_db                                           | 149 kB  00:00:10     
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-15.el7_4.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================
 Package            Arch                 Version                          Repository          Size
===================================================================================================
Installing:
 wget               x86_64               1.14-15.el7_4.1                  base               547 k

Transaction Summary
===================================================================================================
Install  1 Package

Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/wget-1.14-15.el7_4.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for wget-1.14-15.el7_4.1.x86_64.rpm is not installed
wget-1.14-15.el7_4.1.x86_64.rpm                                             | 547 kB  00:00:00     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-5.1804.el7.centos.2.x86_64 (@Updates)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-15.el7_4.1.x86_64                                                     1/1 
install-info: No such file or directory for /usr/share/info/wget.info.gz
  Verifying  : wget-1.14-15.el7_4.1.x86_64                                                     1/1 

Installed:
  wget.x86_64 0:1.14-15.el7_4.1                                                                    

Complete!

1.4、更新容器yum源

#更改yum源
cd /etc/yum.repos.d/
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
 
#重新缓存
yum clean all
yum makecache

1.5、安装常用软件

yum install wget net-tools vim lrzsz screen lsof tcpdump nc mtr nmap -y

1.6、安装nginx

[root@f8988cf8bfda ~]# yum install nginx -y

#编程nginx配置文件,添加参数:daemon off; (备注:关闭在后台运行)
[root@f8988cf8bfda ~]# vim /etc/nginx/nginx.conf
user nginx;
daemon off;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
#保存退出

#检查语法
[root@f8988cf8bfda ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

#运行nginx(按ctrl+c结束)
[root@f8988cf8bfda ~]# nginx

[root@f8988cf8bfda ~]#exit

1.7、查看commit 帮助

[root@docker ~]# docker commit --help

Usage:	docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Create a new image from a container's changes

Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change list      Apply Dockerfile instruction to the created image (default [])
      --help             Print usage
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)

中文:

   OPTIONS说明:
     -a :提交的镜像作者;
     -c :使用Dockerfile指令来创建镜像;
     -m :提交时的说明文字;
     -p :在commit时,将容器暂停。

1.8、docker commit :从容器创建一个新的镜像。

#查看镜像
[root@docker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                         PORTS               NAMES
f8988cf8bfda        centos              "bash"                   24 minutes ago      Exited (127) 2 minutes ago                         upbeat_ardinghelli

#从容器创建一个新镜像,
[root@docker ~]# docker commit -m 'add nginx images' upbeat_ardinghelli nulige/my_nginx
sha256:bfffb39862505e40b411641ad732f84ea1803d63423518b22661b6a4bb34c6a0

#查看镜像
[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nulige/my_nginx     latest              bfffb3986250        17 seconds ago      807 MB   #安装nginx镜像
docker.io/centos    latest              49f7960eb7e4        11 days ago         200 MB   #官网原版镜像
[root@docker ~]# 

#生成打tab号镜像,参数:':v1'  (备注:用他来区分版本)
docker commit -m 'add nginx images' upbeat_ardinghelli nulige/my_nginx:v1

#查看镜像
[root@docker ~]# docker images
REPOSITORY      TAG      IMAGE ID CREATED SIZE
nulige/my_nginx v1      ba1b100081ee About a minute ago 807 MB
nulige/my_nginx latest bfffb3986250 7 minutes ago 807 MB
docker.io/nginx latest cd5239a0906a 10 days ago 109 MB
docker.io/centos latest 49f7960eb7e4 11 days ago 200 MB
docker.io/alpine latest 3fd9065eaf02 5 months ago 4.15 MB

 1.9、登录hub.docker官网

https://hub.docker.com/

注册需要先FQ,才能注册成功,因为要点验证码。邮箱可以填:*****@163.com  (备注:验证可用。)

用户名:nulige

密码:l*********  

2.0、在linux系统中,登录上传制作好的镜像

[root@docker ~]# docker login https://hub.docker.com
Username: nulige
Password: 
Login Succeeded

[root@docker ~]# ls
anaconda-ks.cfg  docker_init.sh

[root@docker ~]# cd .docker/

[root@docker .docker]# ls
config.json
[root@docker .docker]# cat config.json 
{
	"auths": {
		"hub.docker.com": {
			"auth": "bnVsaWdlOmxlbm92b2U0Mg=="
		}
	}

}[root@docker .docker]# pwd
/root/.docker

2.1、搜索别人的镜像

#名称来源于:docker hub
[root@docker ~]# docker search aclstack/mysql INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/mysql MySQL is a widely used, open-source relati... 6386 [OK] docker.io docker.io/mariadb MariaDB is a community-developed fork of M... 2011 [OK] docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 462 [OK] docker.io docker.io/percona Percona Server is a fork of the MySQL rela... 343 [OK] docker.io docker.io/zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 103 [OK] docker.io docker.io/hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 87 docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... 60 [OK] docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... 54 [OK] docker.io docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 36 [OK] docker.io docker.io/tutum/mysql Base docker image to run a MySQL database ... 32 docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 29 docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 28 docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 19 [OK] docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image 15 [OK] docker.io docker.io/linuxserver/mysql A Mysql container, brought to you by Linux... 14 docker.io docker.io/zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 13 [OK] docker.io docker.io/centos/mysql-56-centos7 MySQL 5.6 SQL database server 8 docker.io docker.io/openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6 docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati... 5 docker.io docker.io/mysql/mysql-router MySQL Router provides transparent routing ... 2 docker.io docker.io/openzipkin/zipkin-mysql Mirror of https://quay.io/repository/openz... 1 docker.io docker.io/aclstack/mysql 0 docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 0 [OK] docker.io docker.io/cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release 0 docker.io docker.io/cloudposse/mysql Improved `mysql` service with support for ... 0 [OK]

#上传镜像四步

 2.2、docker 进程有时候容易死机,解决方法: linux supervisor

参考:Linux Supervisor的安装与使用入门

 

posted @ 2018-06-16 15:05  努力哥  阅读(611)  评论(0编辑  收藏  举报