在mac下通过docker搭建LEMP环境境
1.安装virtualbox。由于docker是在lxc环境的容器
2.安装boot2docker,用于与docker客户端通讯
> brew update> brew install docker> brew install boot2docker
3.初始化boot2docker,也就是在virtualbox上安装一个docker的host环境
boot2docker init
此时会下载一个镜像
4.启动虚拟机host
:~$ boot2docker upWaiting for VM and Docker daemon to start.......................oooStarted.To connect the Docker client to the Docker daemon, please set: export DOCKER_HOST=tcp://192.168.59.103:2375 unset DOCKER_CERT_PATH
这样host环境就启动起来了,根据提示设置环境变量
export DOCKER_HOST=tcp://192.168.59.103:2375
后boot2docker就能与host环境的docker客户端连接了
5.连接host环境的docker客户端
MacBook-Pro:~$ boot2docker ssh ## . ## ## ## == ## ## ## ## === /""""""""""""""""\___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/ _ _ ____ _ _| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ ||_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_| boot2docker with VirtualBox guest additions version 4.3.14boot2docker: 1.2.0 master : e75396e - Fri Aug 22 06:03:48 UTC 2014docker@boot2docker:~$
这样我们就成功登录virtualbox中的host环境,便可以进行docker操作了
安装nginx,php,mysql,基于ubuntu14:04,以下我是通过Dockerfile安装的
这里是DockFile
6.生成mysql镜像
Dockerfile
# LEMP stack as a docker containerFROM ubuntu:14.04MAINTAINER Daniel Watrous <email>#ENV http_proxy http://proxy.example.com:8080#ENV https_proxy https://proxy.example.com:8080 RUN apt-get updateRUN apt-get -y upgrade# seed database passwordCOPY mysqlpwdseed /root/mysqlpwdseedRUN debconf-set-selections /root/mysqlpwdseed RUN apt-get -y install mysql-server RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf RUN /usr/sbin/mysqld & \ sleep 10s &&\ echo "GRANT ALL ON *.* TO admin@'%' IDENTIFIED BY 'secret' WITH GRANT OPTION; FLUSH PRIVILEGES" | mysql -u root --password=secret &&\ echo "create database test" | mysql -u root --password=secret # persistence: http://txt.fliglio.com/2013/11/creating-a-mysql-docker-container/ EXPOSE 3306 CMD ["/usr/bin/mysqld_safe"]
mysqlpwdseed
mysql-server mysql-server/root_password password secretmysql-server mysql-server/root_password_again password secret
进入mysql的Dockefile然后生成一个mysql镜像
docker build -t "local/mysql:v1" .