从 Vagrant 到 Docker

最近看了《第一本 Docker 书》,尝试用 docker 来搭一个 lnmp 环境,看看能不能代替 vagrant。


Create Dockerfile

Dockerfile

FROM ubuntu:16.04

RUN echo "mysql-server mysql-server/root_password password root" | debconf-set-selections
RUN echo "mysql-server mysql-server/root_password_again password root" | debconf-set-selections

RUN apt-get update && apt-get install -y \
nginx \
mysql-server \
php7.0-cli \
php7.0-fpm \
php7.0-mysql \
php7.0-curl \
php7.0-gd \
php7.0-mbstring \
php7.0-mcrypt \
php7.0-xml \
php7.0-zip \
curl

EXPOSE 80 443 3306

COPY ./scripts/startup.sh /opt/scripts/startup.sh

CMD ["bash", "/opt/scripts/startup.sh"]

scripts/startup.sh

#!/bin/bash

/etc/init.d/nginx start & /etc/init.d/mysql start & /etc/init.d/php7.0-fpm start

Build

docker build -t lnmp:ubuntu-16.04 .

Run

docker run -it --rm lnmp:ubuntu-16.04

参考:

http://tech.osteel.me/posts/2015/12/18/from-vagrant-to-docker-how-to-use-docker-for-local-web-development.html
http://tech.osteel.me/posts/2017/01/15/how-to-use-docker-for-local-web-development-an-update.html

 597 total views,  2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *