This article will show you how to quickly deploy a PHP + Vue project using docker images. The source code address is provided at the end of the article

Create a Docker mapping directory locally

-- vue_demo # Demo project -- php_vue -- docker-comedy.yaml -- nginx ———— apps # project code ———— conf # nginx configuration file —————— nginx.conf ———— log # nginx ———— vhost # virtual machine configuration directory —————— default.confCopy the code

createdocker-compose.yaml

version : "3" # docker - compose version
services: # collection of containers
      mysql: # Project name
              image: Mysql: 5.7 The build attribute can be used if the image is created from a dockerfile
              container_name: mysql  Docker-compose will randomly assign a name to the container if it does not have this property
              privileged: true    # Allow permission to express the operation, if not added, will be similar to the "permission deny" error
              ports:
                      - 3307: 3306  Open host and container mapping ports
              environment:
                      MYSQL_ROOT_PASSWORD: root  # environment variables in mysql mirror
      php:
              image: PHP: 7.2 - FPM
              container_name: php
              privileged: true
              ports:
                    - 9001: 9000
              links:
                     - mysql  Containers are associated with each other
              volumes:
                     - ./nginx/apps:/usr/share/nginx/html  Nginx will not be able to load PHP as a module, but HTML and other static queries can be accessed normally.
      nginx:
               image:  nginx
               container_name: nginx
               privileged: true
               links:
                       - php
               ports:
                       - 8088: 80
               volumes:
                       - ./nginx/vhost:/www/nginx/vhost
                       - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
                       - ./nginx/log:/www/nginx/log
                       - ./nginx/apps:/usr/share/nginx/html

      phpmyadmin:
              image: phpmyadmin/phpmyadmin
              container_name: phpmyadmin
              privileged: true
              links:
                      - mysql
              ports:
                      - 7001: 80
              environment:
                      MYSQL_ROOT_PASSWORD: root
                      PMA_HOST: mysql

      redis:
              image: Redis: 4.0.14
              container_name: redis
              privileged: true
              ports:
                      - 6379: 6379
      mongo:
              image: mongo
              restart: always
              ports:
                      - 27017: 27017
Copy the code

To create a container, run the docker-compose up -d command

Create a front-end project

Create project vue_demo using vue create vue_demo or Vue UI

Package the vue_demo && NPM run build and copy the dist folder to php_vue/nginx/apps

Test curl localhost:9099 return HTML code

Create a PHP file


      
echo 'hello Docker';
Copy the code

Test curl localhost:8088 return hello Docker

Complicated diseases in the process

The image pulling speed is too slow

Solution – Modify the repository source. Create and modify the /etc/docker-daemon. json file to the following format

/etc/docker/daemon.json {"registry-mirrors": ["http://hub-mirror.c.163.com"]} systemctl restart dockerCopy the code

Domestic acceleration addresses are:

  • Docker China official mirror | registry.docker-cn.com
  • Netease | hub-mirror.c.163.com
  • ustc | docker.mirrors.ustc.edu.cn
  • China university of science and technology | docker.mirrors.ustc.edu.cn
  • Ali cloud | cr.console.aliyun.com

Docker-compose draws the image successfully and does not draw it again. So a mirror appears slow and stuck. Ctrl + C to stop the source switch, restart the docker and run the docker-compose up -d command

Docker failed to create iptables chain

. iptables –wait -t nat -I DOCKER -i br-d38d92300109 -j RETURN:iptables: No chain/target/match by that name.

When the Docker service is started, the Docker service registers a chain with iptables to allow communication between ports exposed by containner managed by the Docker service. You can view the iptables chain using the iptables -l command

In a development environment, if you delete the Iptables Docker chain, or if the iptables rules are lost (e.g., restarting Firewalld), Docker will report an iptables error for example: Failed programming External connectivity… Iptables: No chain/target/match by that name To fix this problem, just restart the Docker service and the correct iptables rules will be created

Program source code

Github.com/ruidao/demo…

Deficiencies & follow-up

  • The above deployment is not fast enough. The correct way to open it is to create your own centos project image
  • Project code iteration can also be a little more automatic