docker lamp

使用docker安装lamp


docker search-s10lamp#搜索被收藏或使用较多的LAMP镜像,小伙伴们都推荐使用tutum/lamp

docker pull tutum/lamp#下载镜像

#使用默认方式启动LAMP

docker run -d -p 8080:80 -p3306: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.获取镜像,启动容器

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

$ docker pull ubuntu:16.04$ docker run-it ubuntu:16.04root@86ea8d701da0:/#2. 在容器中配置所需要的开发环境2.1. 替换阿里云软件更新源

root@86ea8d701da0:/# apt-getupdate

root@86ea8d701da0:/# apt-getinstall -y vim

root@86ea8d701da0:/# vim /etc/apt/sources.list

#16.04deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial main restricteddeb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricteddeb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial universedeb http://mirrors.aliyun.com/ubuntu/ xenial-updates universedeb http://mirrors.aliyun.com/ubuntu/ xenial multiversedeb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiversedeb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-propertiesdeb http://archive.canonical.com/ubuntu xenial partnerdeb-src http://archive.canonical.com/ubuntu xenial partnerdeb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricteddeb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-propertiesdeb http://mirrors.aliyun.com/ubuntu/ xenial-security universedeb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverseroot@86ea8d701da0:/# apt-getupdate2.2. 安装常用软件包

root@86ea8d701da0:/# apt-getinstall -y net-tools curl wget gcc sudo lsof software-properties-common2.3. 安装 AMP 软件

# 安装 MySQL(过程中需要输入数据库的 root 密码)

root@86ea8d701da0:/# apt-getinstall -y mysql-server mysql-client

root@86ea8d701da0:/# usermod -d /var/lib/mysql/mysql

# 安装 Apache2

root@86ea8d701da0:/# apt-getinstall -y apache2

root@86ea8d701da0:/# echo"ServerName localhost">> /etc/apache2/apache2.conf

# 安装 PHP5.6root@86ea8d701da0:/# add-apt-repository ppa:ondrej/php

root@86ea8d701da0:/# apt-getupdate

root@86ea8d701da0:/# apt-getinstall -y php5.6libapache2-mod-php5.6php5.6-dev php5.6-mysql php5.6-gd php5.6-curl php5.6-mbstringphp5.6-xml--allow-unauthenticated注意:需要执行下面几个操作

cat/etc/default/locale

LANG="en_US.UTF-8apt-getinstall language-pack-en

update-locale LANG=en_US.UTF-8root@86ea8d701da0:/# pecl install pdo_mysql# 使用 ps-ef 或 netstat -tlunp 查看 MySQL、Apache

# 如果服务没有自动启动,可使用如下命令手动启动

root@86ea8d701da0:/# service mysql start

root@86ea8d701da0:/# service apache2 start2.5. 验证

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

root@86ea8d701da0:/# apt-getclean

root@86ea8d701da0:/# apt-getautoclean

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 " --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

你可能感兴趣的:(docker lamp)