08-docker 私有镜像制作

1.先pull一个镜像下来,然后启动

[root@docker03 ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
5e35d10a3eba: Pull complete 
Digest: sha256:dcbc4e5e7052ea2306eed59563da1fec09196f2ecacbe042acbdcd2b44b05270
Status: Downloaded newer image for centos:latest
[root@docker03 ~]# docker run -itd --name nginx-web centos
68e8e72880e067fa29f301677b6986e97e9fab26e62044fed87531b1b1e65bb0

2.进入容器,安装软件,配置服务

[root@docker03 ~]# docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
68e8e72880e0        centos              "/bin/bash"         About a minute ago   Up About a minute                       nginx-web

# 进入容器里操作
[root@docker03 ~]# docker exec -it 68e8e72880e0 bash
[root@68e8e72880e0 /]# yum install wget -y
[root@68e8e72880e0 /]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@68e8e72880e0 /]# yum install nginx -y

# 配置nginx前台运行
[root@68e8e72880e0 /]# vi /etc/nginx/nginx.conf
daemon off;

3.镜像制作,打tag

[root@docker03 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
68e8e72880e0        centos              "/bin/bash"         7 minutes ago       Up 7 minutes                            nginx-web
[root@docker03 ~]# docker commit -m 'add nginx server' 68e8e72880e0 sunmmi/nginx
sha256:1fd61459671b30b26fdeda2b3cfbdcfbcad7a150e738ccbf26eb2c1f8f674d41
[root@docker03 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
sunmmi/nginx        latest              1fd61459671b        8 seconds ago       385MB
centos              latest              2d194b392dd1        2 weeks ago         195MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB

4.上传镜像到公有云,前提要在去https://hub.docker.com/ 注册 一个账号

# 登陆hub.docker.com
[root@docker03 ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: sunmxx
Password: 
Login Succeeded

[root@docker03 ~]# cat .docker/config.json 
{
	"auths": {
		"https://index.docker.io/v1/": {
			"auth": "c3VubW1pOndpbnRydHl1bm1leXk="
		}
	},
	"HttpHeaders": {
		"User-Agent": "Docker-Client/17.12.1-ce (linux)"
	}
}

# 镜像打tag
[root@docker03 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
sunmmi/nginx        latest              1fd61459671b        2 minutes ago       385MB
centos              latest              2d194b392dd1        2 weeks ago         195MB
hello-world         latest              f2a91732366c        3 months ago        1.85kB
[root@docker03 ~]# docker tag 1fd61459671b sunmmi/nginx

# push镜像到公有云
[root@docker03 ~]# docker push sunmmi/nginx
The push refers to repository [docker.io/sunmmi/nginx]
ce9286a3b6b9: Pushed 
b03095563b79: Pushed 
latest: digest: sha256:50784e55a050e1fbcee03e5646f1e4dbe37a10329d1e743c158871ce1b7c0b77 size: 741

 5.查看公有云上传的镜像

 

posted @ 2018-03-20 16:24  sunmmi  阅读(145)  评论(0)    收藏  举报