Method 1: docker commit
jiqing@ThinkPad:~$ sudo docker commit 1949036422c3 centos:jiqing
[sudo] password for jiqing:
sha256:4be35dd8f7b4c975c4cf1d35414147ef4dfadbb7a6e1a11f21cebee1ff12428e
jiqing@ThinkPad:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos jiqing 4be35dd8f7b4 11 seconds ago 1.36GB
hello-world latest e38bc07ac18e 3 weeks ago 1.85kB
imagine10255/centos6-lnmp-php56 latest ecc74d703eca 18 months ago 1.31GB
jiqing@ThinkPad:~$ sudo docker run -it centos:jiqing
Starting nginx: [ OK ]
Starting php-fpm: [ OK ]
Starting sshd: [ OK ]
[root@c10a4c3541f5 home]# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02
inet addr:172.17.0.2 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:45 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6345 (6.1 KiB) TX bytes:0 (0.0 b)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Method 2: docker build
jiqing@ThinkPad:~$ sudo mkdir /docker-build
jiqing@ThinkPad:~$ cd /docker-build/
jiqing@ThinkPad:/docker-build$ sudo touch Dockerfile
Note, make automated compilation requires Makefile, and automated docker image requires Dockerfile
FROM centos
MAINTAINER jiqing <[email protected]>
RUN yum -y install httpd
ADD start.sh /usr/local/bin/start.sh
ADD index.html /var/www/html/index.html
Create start.sh and make it executable
echo "/usr/sbin/httpd -DFOREGROUND" > start.sh
chmod a+x start.sh
Create index.html
echo "docker image build test" > index.html
Create custom objects
sudo docker build -t centos:httpd /docker-build
boot image
sudo docker run -it centos:httpd
enable http service
start.sh
View Results