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,中途部署中有點依賴包須要安裝,會在文章中指出php
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