Monday, February 7, 2022

Example Of Dockerfile and docker-compose.yml


Make file of docker-compose.yml

version: "3.7"
services:
  httpd:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8180:80
    links:
      - maria_db:db
    volumes:
      - ./:/app:delegated
      - ./volumes/www.example.com.conf:/etc/apache2/sites-enabled/www.example.com.conf:delegated
      - ./volumes/tech2towards.com.conf:/etc/apache2/sites-enabled/tech2towards.com.conf:delegated
      - ./volumes/logs:/var/log/apache2:delegated
      - ./volumes/custom.ini:/usr/local/etc/php/conf.d/custom.ini:delegated


  maria_db:
    container_name: mariadb
    image: mariadb
    environment:
      MYSQL_DATABASE: demo_db
      MYSQL_ROOT_PASSWORD: docker
    ports:
      - 3306:3306
    expose:
      - "3306"
    volumes:
      - ./volumes/mysql:/var/lib/mysql
      - ./volumes/mysqllogs:/var/log/mysql


  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    links:
      - maria_db:db
    ports:
      - 8181:80
    environment:
      PMA_USER: root
      PMA_PASSWORD: docker



Make file of Dockerfile

FROM php:7.2-apache

#ENV PATH="/app/vendor/bin:$PATH"

# install the PHP extensions we need

RUN apt-get update \
  && apt-get install -y vim \
  && docker-php-ext-install gd mbstring pdo pdo_mysql pdo_pgsql zip intl gmp exif \
  && a2enmod rewrite

RUN a2enmod rewrite \
 && a2enmod headers \

#COPY dev/docker-init-httpd.sh /usr/local/bin/
#RUN ln -s usr/local/bin/docker-init-httpd.sh /docker-init-env.sh # backwards compat
#CMD docker-init-httpd.sh


1) apt-get install docker-compose
2) docker-compose config
3) docker-compose up


Dockerfile For Nodejs


FROM ubuntu:16.04

MAINTAINER Tech2Towards

# 80 = HTTP, 443 = HTTPS, 3000 = NODEJS server
EXPOSE 80 443 9020

ENV PORT 9020

# Install Utilities
RUN apt-get update -q  \
 && apt-get install -yqq \
 curl \
 sudo \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install nodejs
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
RUN sudo apt-get install -yq nodejs \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install NODEJS Prerequisites
#RUN npm install --quiet -g pm2 && npm cache clean
RUN npm install --quiet -g pm2

RUN mkdir -p /opt/tech-frontend
WORKDIR /opt/tech-frontend

# Copies the local package.json file to the container
# and utilities docker container cache to not needing to rebuild
# and install node_modules/ everytime we build the docker, but only
# when the local package.json file changes.
# Install npm packages

COPY package.json /opt/tech-frontend/package.json

#RUN npm install --quiet && npm cache clean
RUN npm install --quiet --silent

COPY . /opt/tech-frontend

# Run NODEJS server
CMD npm install

CMD ["pm2-docker","server.js"]
 

No comments:

Post a Comment

testing