我使用的是centos7.0系统,具体安装要求,大家可以去官网上查询
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 #安装工具,我安装docker的时候并没有安装,也没出现错误,不知道是不是环境的问题 sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #添加源信息 sudo yum makecache fast # 更新yum缓存 sudo yum -y install docker-ce #安装ce版本 sudo systemctl start docker #启动docker上面的安装方式是直接安装,代码和配置文件都在容器中,修改不方便,可以用下面的方式运行容器
mkdir -p /data/www/html /data/nginx/conf /data/nginx/logs #创建个人目录,保存文件信息 docker cp 6dd4380ba708:/etc/nginx/nginx.conf /data/nginx/conf #从一个成功运行的nginx容器中把配置文件复制过来 docker run -d -p 80:80 --name nginx-web -v /data/www/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/logs:/var/log/nginx nginx #创建新的容器,将配置文件挂载到刚才创建的文件中然后在/data/www/html中编辑文件,即可以访问
在目录中添加test.conf文件,文件内容如下:
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name; include fastcgi_params; } } docker run --name php-nginx-web -p 80:80 -d \ -v /data/www/html:/usr/share/nginx/html:ro \ -v /data/nginx/conf.d:/etc/nginx/conf.d:ro \ --link php-72:php \ nginx #创建新的nginx和php关联容器,注意其他nginx容器最好关闭,php容器一定要打开然后在/data/www/html中书写index.php,就可以正常应用了
