Docker Base Image Creation
In the learning attitude, want to understand the creation of Docker Base image method, in the official website, in Baidu, in the relevant forums, find relevant information, here record the implementation of the steps,
I. Environment
Host operating system: OS X, need to install VirtualBox;
Container environment: CENTOS7
two. Install the system with VirtualBox, take CentOS 7 for example (Centos-7-x86_64-minimal-1503-01.iso)
To create a virtual machine and install CENTOS7, the detailed installation process is documented below.
* Installation process is simple, I have a slow speed here, not on the map, there is a need for friends to leave a mailbox, I send PDF. *
After installation, reboot and enter the system.
Three. Modify Network configuration
Modify the network configuration/etc/sysconfig/network-script/ifcfg-enp0s3.
Delete uuid,hwaddr
, modify Onboot=no to Onboot=yes, and then save.
$ ifconfig
Cannot find a valid baseurl for Repo:base/7/x86_6
Restart network interface:
[root@centos7 ~] #ifdown enps03
[Root@centos7 ~]# Ifup enps03
$ yum Install ifconfig
hint: Nothing to do
lists the package with the Yum provides command
$ ifconfig yum s ifconfig
//Installation
$ yum-y Install Net-tools
Four. Install Docker
Install Epel (reference: http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/)
[Root@centos7 ~]# rpm- UVH http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
Modification/etc/yum.repos.d/ Centos-base.repo Enabled=0 changed to enabled=1
Vim/etc/yum.repos.d/centos-base.repo
[Centosplus]
enabled =1
installation Docker
[Root@centos7 yum.repos.d]# yum install
boot docker-io docker
[Root@centos7 yum.repos.d]# Service Docker start
Five. Create an underlying mirror
The substitution variable replaces the $releasever in the/etc/yum.repos.d/centos-base.repo file with a 7 $basearch replaces the x86_64 Quick Replace method: vim/etc/yum.repos.d/centos- Base.repo:%s/$releasever/7/g:%s/$basearch/x86_64/g Create Docker image build script [Root@centos7 yum.repos.d]# cd/root [root@cent OS7 ~]# mkdir scripts [root@centos7 ~]# cd scripts/[Root@centos7 scripts]# vim createimage.sh then turn https://github.com/dock Er/docker/blob/master/contrib/mkimage-yum.sh the content in the file [Root@centos7 scripts]# chmod +x createimage.sh Create Image [ Root@centos7 scripts]#./createimage.sh Centos7base After successful creation, view and delete the currently running container [Root@centos7 tmp]# Docker images] REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos7base 7.1.1503 112ee00c2cbc 8 minutes ago 227.7 MB [Root@centos7 tmp]# Docker ps-all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 752b9d49a079 centos7base:7.1.1503 "echo success" minutes ago exited (0) minutes ago M Ad_saha [Root@centos7 tmp]# DockER rm 752b9d49a079 752b9d49a079 [Root@centos7 tmp]# Docker ps-all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES export Image [Root@centos7 tmp]# cd/tmp/[Root@centos7 tmp]# Docker Images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos7base 7.1.1503 112ee00c2cbc minutes ago 227.7 MB [Root@centos7 tmp]# docker save 112EE00C2CBC >/tmp/centos7base.tar [root@centos7 tmp]# ls Centos7base.tar KS-SCRI
Pt-l8tdo5 Yum.log [Root@centos7 tmp]#
Six. Docker Common commands
Docker Stop <container id>: A container used to stop running, and you can also use
docker start <container Id>: To start a container that has stopped.
Docker restart <container id>: You can restart a running container. This is equivalent to the first stop and start of a container.
Docker attach <container id>: Associating to a running container
delete Mirror: Docker rmi <image id> Docker
RMI 2db1e85f26ba< c7/> Delete containers: Docker rm <container id>
Docker rm c3bfb652a491
View the running container
Docker ps-all
stop container:
Exit
back into window
docker start <container id>
Docker attach <container id>
temporary exit container
CTRL + P then CTRL + Q
Re-enter:
Docker attach <container id>
Save the container as a mirror:
Docker commit <container ID > <NAME>:<TAG>
Seven. Guide to the local mirror library
Go back to the host, copy the image exported from the virtual machine to the local hr:~ hr$ mkdir-p docker/images hr:~ hr$ cd docker/images/hr:images hr$ SCP Root@192.168.1.4:/tm
P/centos7base.tar.
Hr:images hr$ Ls-lah Total 469392 drwxr-xr-x 3 hr staff 102B 12 5 21:08.
Drwxr-xr-x 3 HR Staff 102B 12 5 21:05. -rw-r--r--1 hr Staff 229M 5 21:08 centos7base.tar boot docker Quick start Terminal load image package to Docker image Hr:images hr$ Docker Load </users/hr/docker/images/centos7base.tar hr:images hr$ Docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE <none> <none> 112ee00c2cbc minutes ago 227.7 MB hello- World latest 975B84D108F1 7 weeks ago 960 B TAR equals none is just imported, change the tag name: Hr:images hr$, docker tag 112ee0 0C2CBC centos7base:7.1 hr:images hr$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE cen Tos7base 7.1 112ee00c2cbc minutes ago 227.7 MB Hello-world latest 975B84D108F1 7 weeks AG O 960 B Run Container: hr:images hr$ Docker run-i-T 112ee00c2cbc/bin/bash [ROOT@E948ACAE7B42/]# hostname e948acae7b42 [root@e948
Acae7b42/]# cat/etc/redhat-release CentOS Linux release 7.1.1503 (Core)
Eight. Release mirror to Docker hub
The premise is to register an account first: https://hub.docker.com/
1. Login
Docker login-username=< User name >-email=< email address >
2. Docker REPOSITORY required to modify the mirror tag
Docker tag <image id> user name/mirror name/tag
Docker tag 112EE00C2CBC honor/centos7base:7.1
3. Upload
Docker Push Honor/centos7base
Thank you for reading, I hope to help you, thank you for your support for this site!