# build environment

FROM node:alpine as builder

RUN npm install nodemon -g — save

WORKDIR /app

COPY . .

RUN npm cache clean — force

RUN npm i

# dev

# EXPOSE 3000 < Is defualt post not setup

CMD [ “npm”, “run”, “start” ]

#production

# RUN npm run build

# # nginx state for serving content

# FROM nginx:1.19.0

# # Set working directory to nginx asset directory

# WORKDIR /usr/share/nginx/html

# # Remove default nginx static assets

# RUN rm -rf ./*

# # Copy static assets from builder stage

# COPY — from=builder /app/build .

# # Containers run nginx with global directives and daemon off

# ENTRYPOINT [“nginx”, “-g”, “daemon off;”]

--

--

docker-compose.yml

mongo-express:

image: mongo-express

volumes:

- ./config.default.js:/node_modules/mongo-express/config.js

environment:

# — ME_CONFIG_MONGODB_SERVER=”url.mongo1,url.mongo2,url.mongo3"

# — ME_CONFIG_MONGODB_URL=’mongodb://mongo1:27017,mongo2:27017,mongo3:27017/bl?replicaSet=my-mongo-set’

# — ME_CONFIG_MONGODB_SERVER=”mongo1:27017,mongo2:27017,mongo3:27017"

# — ME_CONFIG_MONGODB_SERVER=mongo

- ME_CONFIG_MONGODB_SERVER=mongo1:27017,mongo2:27017,mongo3

- ME_CONFIG_MONGODB_PORT=27017

- ME_CONFIG_MONGODB_ENABLE_ADMIN=true

- ME_CONFIG_MONGODB_AUTH_DATABASE=test

# — ME_CONFIG_MONGODB_AUTH_USERNAME=root

# — ME_CONFIG_MONGODB_AUTH_PASSWORD=example

- ME_CONFIG_BASICAUTH_USERNAME=dev

- ME_CONFIG_BASICAUTH_PASSWORD=dev

# — ME_CONFIG_MONGODB_ADMINUSERNAME=”admin”

# — ME_CONFIG_MONGODB_ADMINPASSWORD=”admin”

# depends_on:

# — mongo

ports:

- “8081:8081”

networks:

- backend-network

Edit config.default.js

function getConnectionStringFromEnvVariables() {

….

Fix : return ‘mongodb://mongo1:27017,mongo2:27017,mongo3:27017/test?replicaSet=my-mongo-set’;

}

--

--

Nginx + docker-compose + php get .env

ก่อนอืนต้องบอกว่า โดย default การใช้ php get .env มาใช้งานนั้นจะถูกปิดกั้นอยู่แล้วเราต้องเปิดถึงจะสามารถดึงค่า .env มาใช้งานได้

Step #1

Edit /etc/php/7.3/php-fpm.d/www.conf โดย clear_env = no

Step #2

Edit php.ini uncomment variables_order = “EGPCS”

Step #3

restart enjoy get .env

--

--