原文地址: http://www.cnblogs.com/uglyliu/p/6137897.html
 
docker search -s 10 lamp  #搜索被收藏或使用较多的LAMP镜像,小伙伴们都推荐使用tutum/lamp
docker pull tutum/lamp   #下载镜像
 
#使用默认方式启动LAMP
docker run -d -p 8080:80 -p 3306:3306 tutum/lamp
 
#友提,如果报bind:address already in use的错误,那就重新选择一个新的host_port(-p host_port:container_port)做为映射端口

 感觉写的不错,补充下,转载:https://github.com/whorusq/docker-learning/tree/master/lamp1#lamp1基于-虚拟机-形式的-fat-container,中途部署中有点依赖包需要安装,会在文章中指出

复制代码
lamp1(基于 虚拟机 形式的 Fat Container)

单一进程容器,又被称为 Fat Container ,类似虚拟机,不推荐
1.获取镜像,启动容器

这里使用官方镜像 Ubuntu 16.04,采用加速器 daocloud.io 以解决国内访问 docker-hub 慢的问题,也可以采用阿里云镜像加速器

$ docker pull ubuntu:16.04
$ docker run -it ubuntu:16.04
root@86ea8d701da0:/#
2. 在容器中配置所需要的开发环境

2.1. 替换阿里云软件更新源

root@86ea8d701da0:/# apt-get update
root@86ea8d701da0:/# apt-get install -y vim
root@86ea8d701da0:/# vim /etc/apt/sources.list
 
# 16.04
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

root@86ea8d701da0:/# apt-get update
2.2. 安装常用软件包

root@86ea8d701da0:/# apt-get install -y net-tools curl wget gcc sudo lsof software-properties-common
2.3. 安装 AMP 软件

# 安装 MySQL(过程中需要输入数据库的 root 密码)
root@86ea8d701da0:/# apt-get install -y mysql-server mysql-client
root@86ea8d701da0:/# usermod -d /var/lib/mysql/ mysql

# 安装 Apache2
root@86ea8d701da0:/# apt-get install -y apache2
root@86ea8d701da0:/# echo "ServerName localhost" >> /etc/apache2/apache2.conf

# 安装 PHP5.6
root@86ea8d701da0:/# add-apt-repository ppa:ondrej/php
root@86ea8d701da0:/# apt-get update
root@86ea8d701da0:/# apt-get install -y php5.6 libapache2-mod-php5.6 php5.6-dev php5.6-mysql php5.6-gd php5.6-curl php5.6-mbstring php5.6-xml --allow-unauthenticated

注意:需要执行下面几个操作
cat /etc/default/locale
LANG="en_US.UTF-8
apt-get install language-pack-en
update-locale LANG=en_US.UTF-8

root@86ea8d701da0:/# pecl install pdo_mysql

# 使用 ps -ef 或 netstat -tlunp 查看 MySQL、Apache
# 如果服务没有自动启动,可使用如下命令手动启动
root@86ea8d701da0:/# service mysql start
root@86ea8d701da0:/# service apache2 start
2.5. 验证

root@86ea8d701da0:/# curl localhost
3. 清理垃圾

root@86ea8d701da0:/# apt-get clean 
root@86ea8d701da0:/# apt-get autoclean 
root@86ea8d701da0:/# rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/log/apache2/* /var/log/mysql/*
root@86ea8d701da0:/# echo /dev/null > ~/.bash_history
4. 提交变更

# 命令基本语法
docker commit [选项] <容器ID或容器名> [<仓库名>[:<标签>]]

# 查看当前运行中的容器
$ docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
86ea8d701da0        ubuntu:16.04        "/bin/bash"         53 minutes ago      Up 53 minutes                           priceless_clarke

# 提交已经修改的容器为新的镜像
$ docker commit --author "whoru.S.Q <whoru.sun@gmail.com>" --message "init" 86e lamp:v1

# 查看镜像列表
$ docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
lamp                 v1                  fa80dfae1af0        8 minutes ago       875 MB
ubuntu               16.04               0ef2e08ed3fa        8 weeks ago         130 MB
5. 以新镜像启动容器

# 映射为 8888 端口;本地 www 目录
$ docker run -idt -p 8888:80 -v ~/www:/var/www/html lamp:v1
e629b4c8bb3e3c1c3491e9da2f4a230a22e5172bddaaeb0ced8c3b807393ca2c

# 既然容器手动启动一下服务
$ docker exec -it e62 /bin/bash
root@e629b4c8bb3e:/# service apache2 start
root@e629b4c8bb3e:/# exit

浏览器访问:localhost:8888
复制代码

 

天天向上,空杯心态。
---------------------------------------------------------------------------------------------
不忘初心 方得始终!

唯有志存高远,方能风行天下。

道之所存,虽千万人吾往矣! 情之所钟,虽千万里吾念矣~

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。