I have a docker application on my localhost which works fine. I am running PHP, Nginx and Mariadb on it.
The docker-compose.yml
file which containes this code:
version: '3'
services:
db:
build:
context: ./mariadb
volumes:
- "./.data/db:/var/lib/mysql"
- "./logs/mariadb:/var/log/mysql"
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
networks:
- default
php-fpm:
build:
context: ./php7-fpm
args:
TIMEZONE: ${TIMEZONE}
volumes:
- ${APP_PATH}:/var/www/app
environment:
DB_HOST: db
DB_PORT: 3306
DB_DATABASE: ${MYSQL_DATABASE}
DB_USERNAME: ${MYSQL_USER}
DB_PASSWORD: ${MYSQL_PASSWORD}
depends_on:
- db
networks:
- default
nginx:
build:
context: ./nginx
args:
- 'php-fpm'
- '9000'
volumes:
- ${APP_PATH}:/var/www/app
- ./logs/nginx/:/var/log/nginx
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
networks:
- default
networks:
default:
driver: bridge
At first I thought there was only one compose file required, and when I built the image, pushed it to docker hub and then pulled that image on my production server, the container failed to launch.
I did some reading and there are many online sources suggesting to use, from 1 to 4 docker file, and to check out two git branches.. among other things ...
I understand that I should at least create one more file called docker-compose-prod.yml
, and in that file, I should omit the volumes:
and port:
attributes, but it seems there is no clear guide on:
how to make docker work on local
exactly when and how to build a container for production.
Can someone clear this up for me please?