Git Product home page Git Product logo

docker's Introduction

Docker setup

The Docker environment project.

Directory structure

├─ docker-compose.yml
│
├─ mysql
│   └─ my.cnf
├─ nginx
|   ├─ conf.d
|   ├─ ...
│   └─ Dockerfile
│
├─ php
|   ├─ config
|   ├─ ...
│   └─ Dockerfile
│
├─ .env
│

Setup manual

1. Install Docker Desktop on Windows:

(*) Requires Microsoft Windows 10 Professional or Enterprise 64-bit, or Windows 10 Home 64-bit with WSL 2.

2. Modify project path

Copy and rename the '.env.example' file to '.env'.

Modify the source directory in .env file.

SOURCE_PATH=<SOURCE DIRECTORY>
VOLUME_PATH=/var/www/html
  • Application will be mounted to /var/www/html

You may modify project paths in above directory with your local paths.

Eg:

SOURCE_PATH=C:\workspace\laravel-react-project
  • Modify others configurations if needed.
    eg: you can modify the port number of http/https instead of the default configuration shown below.
APP_PORT=80
APP_SSL_PORT=443

3. Check configuration of Nginx server

Directory docker\nginx\conf.d\default.conf

server {
    ...
    root  /var/www/html/public;
    ....
    location ~ \.php {
      fastcgi_pass            docker_phpfpm_1:9000;
    ...
    }
}

Explain

  • root : the VOLUME_PATH, the project mounted directory
  • docker_phpfpm_1 : phpfpm containner, the generated default name

4. Build docker

By using window command line ..etc

1/ Go to docker's directory.
2/ Build image by command.

docker-compose build

3/ Build containner.

docker-compose up

if it's all successed, all the services are running as image below Mount

5. Access local site

http://localhost/

  • if the default port 80/443 has modified in .env file, it's must be specified in the url properly.

Useful commands inside container

Get inside a containner eg:

    docker exec -it docker_nginx_1 bash
    docker exec -it docker_phpfpm_1 bash

To update composer packages

composer install

Show docker images (run on host machine)

docker ps

Inspect a container (run on host machine)
eg : check container service redis

docker inspect redis

Check docker network (run on host machine)

docker network ls

Remove specific docker network (run on host machine)

docker network rm NETWORK [NETWORK...]
  • (Optional) Cleanup build folder (run on host machine):
docker system prune
  • (Optional) Show all images (run on host machine):
docker images
  • (Optional) Clean all images and containers (run on host machine):
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)

Modify the DB mysql connection of laravel-react-project

  1. In .env file, modify the config:
DB_CONNECTION=mysql
DB_HOST=172.20.0.5
DB_PORT=3306
DB_DATABASE=frappe_dev
DB_USERNAME=root
DB_PASSWORD=password

Explain 172.20.0.5 : the configured ip in .env file, specifically it's the value of MYSQL_IPV4_ADDRESS

Common errors and how to solve

  1. ERROR: Pool overlaps with other one on this address space Mount

the docker subnet mark is already in use
So, remove the confict network or changing the config in .env file and build again!

Remove the confict network by following commands

docker network ls
docker network rm NETWORK_NAME

changing the ip config in .env file.

DOCKER_SUBNET=172.20.0.0/16
NGINX_IPV4_ADDRESS=172.20.0.2
PHPFPM_IPV4_ADDRESS=172.20.0.3
REDIS_IPV4_ADDRESS=172.20.0.4
MYSQL_IPV4_ADDRESS=172.20.0.5 

docker's People

Contributors

ngovandiep avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.