docker installed php, nginx, redis, mysql and link up the container

The people have the nerve to say that they are original, I also served, pits and more, we have modified

I built the php7

 

docker 安装php,nginx,redis,mysql容器并且link起来

    docker pull mysql
    docker pull nginx
    docker pull redis
    docker pull php:7.0-fpm


    需要制定版本的可以像php那样加版本号,没加的就是最新的


Operating environment
MacBook Pro, OSX 10.13.6

start php-fpm
interpreted php need php-fpm, let it up and running:

docker run --name php7 -d  -v  /home/www:/www/wwwroot php:7.0-fpm

解释执行 php 需要 php-fpm,先让它运行起来:

说明:
php7 是容器的名字

~/home/lnmp/www  宿主机目录

/www/wwwroot     目录名字


 

启动mysql
 docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6

加版本,如果上面没有的话又会下载一遍

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql

所以最好不要加版本

-name container name

mysql custom name

-p: exposure port, the port mapping (mapping can be multiple ports) external ports: port inside of the container

-p 3306: 3306 port mapping

-e: set any environment variables (the vessel)

MYSQL_ROOT_PASSWORD = root here refers to set the database password for the root

start redis

docker run --name redis -p 6379:6379 -d redis

redis custom name 
-p 6379: 6379 port mapping, i.e. external ports: a container port 
redis: Latest image name: version

within nginx, php-fpm, mysql, redis container link

docker run --name nginx --link mysql:db --link redis:redis --link php7:php -p 80:80 -v /home/www:/www/wwwroot -d nginx

Edit the nginx configuration file

The docker conf.d cp vessel in a configuration file to the local default.conf 
docker cp nginx: /etc/nginx/conf.d/default.conf default.conf 

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /www/wwwroot;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root          /www/wwwroot;
        fastcgi_pass   172.17.0.2:9000; #php-fpm容器的ip,端口9000
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /www/wwwroot/$fastcgi_script_name;
        include        fastcgi_params;

    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

查看容器ip 的方法

docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-ID> 
或 
docker inspect <container id> 
或 
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id!

 

Modify the copy can go back docker cp default.conf nginx: /etc/nginx/conf.d/default.conf
These are my profile
launch container
docker start nginx
closed container
docker stop nginx
restart the container
docker restart nginx
delete container
docker rm nginx
into the container
docker exec -it nginx / bin / bash
container status
docker status nginx
view mirror
Docker ImagesRF Royalty Free
Docker container to view running
docker ps
view all containers
docker ps -a
remove the mirror
docker rmi nginx
export export
1. first check all containers
sudo docker ps -a
2. find cONTAINER ID to export container, and then execute the command
sudo docker export container cONTAINER ID> export address file name
that is
sudo docker export 234wer2323dfdfdsfq> /home/export.tar
Import Import
CAT /home/export.tar | sudo Docker Import - lanmps: Latest
save the Save
the Save command for persistent image (not the container)
1. The first check all mirrors
sudo docker images

2. Find the image you want to save the name of
sudo docker save image name> to save the address of the file name
that is
sudo docker save lanmps> /home/save-lanmps.tar
loaded
docker load </home/save-lanmps.tar
last visit localhost: 8888 on can show directory access
using redis
To use it you must install redis redis container in php extension
redis extended download connection 
phpize 
./configure 
the make the make install && 
this time compiler installation, and then generates a redis.so extension of this time to ask his profile where is it? 
His profile /usr/local/etc/php/conf.d thrown directly below

redis.ini file name
extension = / usr / local / lib / php / extensions / no-debug-non-zts-20170718 / redis.so
restart php-fpm container
Docker the restart php72
localhost: 8888 / the index.php
echo the phpinfo () ;

Find redis extension has been installed
to write sections of the code it

the Redis Redis new new = $ ();
$ redis-> Connect ( '172.17.0.5', 6379); // vessel IP
// print_r ($ Redis); Die;
$ = strName 'Push';
$ Re = $ redis- > publish ($ strname, "from small series to write their own {$ strname} push!");
echo "{$ strname} ---- ----- successful push /> <br";
$ redis-> use Close ();
MySQL use
the try {
    $ DB = new new the PDO ( 'MySQL: Host = 172.17.0.4; dbname = Test', 'the root', 'the root');
    $ ARR = $ db-> Query ( "SELECT * from User ") -> FETCH ();
    var_dump ($ ARR); Die;
} the catch (PDOException $ E) {
    Print" Error: a ";" $ E-> the getMessage ().. "
    Die ();
}
original: https: //blog.csdn. net / qq_36373262 / article / details / 79727223
own pro-test, part of the pit has been filled

Published 29 original articles · won praise 5 · Views 8003

Guess you like

Origin blog.csdn.net/qq_25194685/article/details/89742199