Jamyy's Weblog

在 Container 運行 httpd

by Jamyy on 四月.23, 2015, under Linux

  • 在 CentOS 6 container 運行 httpd
  • 在 CentOS 7 container 運行 httpd
  • 將本地 image 複製到其他主機

操作環境: Ubuntu Desktop 15.04 x64, docker.io 1.5.0

在 CentOS 6 container 運行 httpd

$ docker pull centos:6.6
$ docker run -it centos:6.6 /bin/bash
# yum -y install httpd
# chkconfig httpd on
# exit
$ docker commit xxxxxxx centos6:httpd
$ docker rm -f xxxxxxx
$ docker run -d -p 8080:80 centos6:httpd /sbin/init
$ curl http://localhost:8080

在 CentOS 7 container 運行 httpd (host 必須是 systemd 環境)

$ git clone https://github.com/maci0/docker-systemd-unpriv
$ cd docker-systemd-unpriv
$ ./build.sh
$ ./run.sh
$ docker exec -it xxxxxxx /bin/bash
# yum -y install httpd
# systemctl enable httpd.service
# exit
$ docker commit xxxxxxx centos7:httpd
$ docker rm -f xxxxxxx
$ docker run -d -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 8080:80 centos7:httpd /usr/lib/systemd/systemd
$ curl httpd://localhost:8080

將本地 image 複製到其他主機

@ local
$ docker save centos6:httpd > /path/centos6-httpd.tar
$ scp /path/centos6-httpd.tar someone@remote:/path/
$ ssh someone@remote

@ remote
$ docker load < /path/centos6-httpd.tar
$ docker run -d -p 8080:80 centos6:httpd /sbin/init
$ curl http://localhost:8080



Ref:



: