Docker手动配置Lamp镜像

时间:2021-01-16 16:59:06

在Docker Hub上找了很多Lamp的镜像

网上都说tutum的镜像做的还是不错的

Docker手动配置Lamp镜像

试试

折腾了一上午无果。。。

Docker手动配置Lamp镜像

算了,自己动手吧


  • pull一个官方的ubuntu镜像下来作为最基础的镜像

root@VM-149-127-debian:~# docker pull ubuntu:latest

  • 从这个镜像运行一个容器

root@VM-149-127-debian:~# docker run -itd ubuntu /bin/bash

Docker手动配置Lamp镜像

从这个容器里搭建一个Lamp环境

  • 首先更新一下

root@6b7e6d0e6c52:/# apt-get update

  • 安装一些可能会用到的工具

root@6b7e6d0e6c52:/# apt-get –y install vim wget curl python2.7 python3 default-jdk git openssh-server

  • 建议换成国内源,速度比较快

root@6b7e6d0e6c52:/# vim /etc/apt/source.list

#中科大:

deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

#清华大学:

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse

#阿里云

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted

deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties

deb http://mirrors.aliyun.com/ubuntu/ xenial universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties

deb http://archive.canonical.com/ubuntu xenial partner

deb-src http://archive.canonical.com/ubuntu xenial partner

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties

deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

  • 安装pip

root@6b7e6d0e6c52:/# wget https://bootstrap.pypa.io/get-pip.py && python2.7 ./get-pip.py && python3 ./get-pip.py && rm ./get-pip.py

  • 安装Maven

root@6b7e6d0e6c52:/# cd /usr/local && wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz

root@6b7e6d0e6c52:/# tar xzf apache-maven-3.5.0-bin.tar.gz && ln -s apache-maven-3.5.0 apache-maven

root@6b7e6d0e6c52:/# vim /etc/profile.d/apache-maven.sh

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
export M2_HOME=/usr/local/apache-maven
export PATH=${M2_HOME}/bin:${PATH}
root@6b7e6d0e6c52:/# source /etc/profile.d/apache-maven.sh
  • 可以开始搭建Lamp环境了
    • 安装Mysql

root@6b7e6d0e6c52:/# apt-get –y install mysql-server mysql-client

    • 安装Apache2

root@6b7e6d0e6c52:/# apt-get –y install apache2

    • 安装PHP

root@6b7e6d0e6c52:/# apt-get –y install php7.0

    • 安装PHP扩展

root@6b7e6d0e6c52:/# apt-get –y install libapache2-mod-php7.0 libapache2-mod-php php7.0-mysql php7.0-curl php7.0-json php7.0-cgi php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-snmp php7.0-tidy php7.0-xmlrpc php7.0-xsl

    • 安装phpmyadmin

root@6b7e6d0e6c52:/# apt-get install phpmyadmin && cp /usr/share/phpmyadmin /var/www/html -a

    • 重启Apache

root@6b7e6d0e6c52:/# service apache2 restart

  • Lamp环境已经搭建完成了,测试一下

root@6b7e6d0e6c52:/# curl 127.0.0.1

Docker手动配置Lamp镜像

Good!

  • 退出这个容器,使用commit命令从这个容器创建一个镜像

Ctrl+p+q

root@VM-149-127-debian:~# docker commit 6b7e srpopty/lamp

6b7e是刚才创建的容器,后面是镜像的标签

过程比较慢。。。。。

  • 成功!

Docker手动配置Lamp镜像

f67b7ba76dca63c2a25babc666340c3148dea08c64c400eadbb9b25b34d0e480

就是生成的镜像

772MB,可能装的库有点多

  • 测试一下

root@VM-149-127-debian:~# docker run –itd –p 1234:80 f67b /bin/bash

Docker手动配置Lamp镜像

进容器看看

root@VM-149-127-debian:~# docker attach d553

Docker手动配置Lamp镜像

原来服务没开,嗯。。。或许可以设定成自启动

打开服务

root@d5534be976a6:/# service apache2 start

出现报错

* Starting Apache httpd web server apache2                                                                                             AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
*

解决办法

root@d5534be976a6:/# vim /etc/apache2/apache2.conf

在最后一行加上

#Server Name

ServerName 127.0.0.1:80

保存退出,重启apache再试试

Docker手动配置Lamp镜像

Good!

  • 现在Lamp镜像就做好了,别忘记删除中间容器

Docker手动配置Lamp镜像


这个方法有个很大的缺点,因为自己动手制作的lamp镜像是基于ubuntu的子镜像,所以原来的ubuntu镜像是不能删除的,不过留着就留着吧,以后制作基于ubuntu的其他镜像的时候也方便。