To create a CentOS Docker mirror with Apache service using Dockerfile _docker

Source: Internet
Author: User
Tags ssh centos docker ps docker run

Using Dockerfile to create CentOS Docker mirrors with Apache services

List of files prepared on the host:

Dockerfile

#启动ssh和apache服务的角本
run.sh

The above files are placed in the/root/apache_centos directory

Mkdir-p/root/apache_centos
Cd/root/apache_centos

Base mirroring: Mirroring of open SSH services based on mirrored CentOS

[Root@localhost apache_centos]# Docker images
REPOSITORY     TAG         IMAGE ID      CREATED       VIRTUAL SIZE
sshd        dockerfile     411d5fb16366    hours ago    278 MB
CentOS       latest       0f73ae75014f    5 weeks ago     172.3 MB

I. Preparation of RUN.SH documents

Create a new run.sh in the/root/apache_centos directory

Vim run.sh

The contents are as follows:

#!/bin/bash
/usr/sbin/sshd &
/usr/local/apache2/bin/httpd-d foreground

Second, prepare Dockerfile

Create a new dockerfile in the/root/apache_centos directory

Vim Dockerfile

The contents of the document are as follows:

#新生成的镜像是基于sshd:d ockerfile Mirror from
sshd:dockerfile
maintainer by Steven
#安装wget
RUN yum install-y wget
workdir/usr/local/src
#下载并解压源码包
run wget http://apache.fayea.com/httpd/httpd-2.4.17.tar.gz
run TAR-ZXVF httpd-2.4.17.tar.gz
workdir httpd-2.4.17
#编译安装apache
RUN yum install-y gcc make apr-devel Apr AP R-util apr-util-devel pcre-devel
RUN./configure--prefix=/usr/local/apache2--enable-mods-shared=most-- Enable-so
Run make
run make install
#修改apache配置文件
run sed-i ' s/#ServerName www.example.com:80/ ServerName localhost:80/g '/usr/local/apache2/conf/httpd.conf
#启动apache服务
run/usr/local/apache2/bin/ httpd
#复制服务启动脚本并设置权限
ADD run.sh/usr/local/sbin/run.sh
run chmod 755/usr/local/sbin/run.sh
# Open 80-Port
expose
CMD ["/usr/local/sbin/run.sh"]

Note that replacing the current directory in the Dockerfile file cannot be made with the "CD" command, but instead "Workdir".

Third, generate mirrors

Docker build-t Apache_dockerfile:centos.

To view the generated mirrors:

[Root@localhost apache_centos]# Docker images
REPOSITORY     TAG         IMAGE ID      CREATED       VIRTUAL SIZE
Apache_dockerfile  CentOS       f8f30b4a0ee8    minutes ago   440 MB
Apache       CentOS       F92c55dddd07    hours ago    423.9 MB
sshd dockerfile 411d5fb16366 #    hours ago    278 MB
centos       latest       0f73ae75014f    5 weeks ago     172.3 MB

Iv. build containers based on mirroring and test

1. Generate New containers

 Docker run-d-P 2222:22-p 8000:80 apache_dockerfile:centos/usr/local/sbin/run.sh

Map the container's 22 and 80 ports to 2222 ports and 8000 ports on the host, and run the service script.

2. View newly generated containers:

[Root@localhost apache_centos]# Docker ps-a
CONTAINER ID    IMAGE           COMMAND        CREATED       STATUS           PORTS                    NAMES
ae560e497f39    apache_dockerfile:centos  "/usr/local/sbin/run-  seconds ago        up seconds 0.0.0.0:2222->22/tcp, 0.0.0.0:8000->80/tcp  condescending_bardeen
6490CD244C10    apache:centos       "/usr/local/apache2/  hours ago exited    (0) hours ago                         Loving _wright
673e946b57e4    sshd:dockerfile      "/usr/local/sbin/run  hours ago    exited (137) # 17 Hours ago                        Reverent_bell

3, testing

Test Apache

[root@localhost apache_centos]# Curl localhost:8000
 
 

Success!

Testing SSH

[root@localhost apache_centos]# ssh localhost-p 2222
root@localhost ' s password:

Success!

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.