Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Friday, September 10, 2021

Apache on Ubuntu

Dockerfile for installing Apache on Ubuntu:

FROM ubuntu:20.04

ENV TZ=Europe/Berlin

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update && apt-get -y install apache2

EXPOSE 80

CMD ["/usr/sbin/apachectl", "-D", "FOREGROUND"]

Build and run

docker build -t ubu-apache .
docker run --name=ubu-apache -d -p 80:80 -v $(pwd)/html/:/var/www/html/ ubu-apache

Enter in container. Tail logs and list files in html folder

docker exec -it ubu-apache /bin/bash

root@8c138884f9a3:/# tail -f /var/log/apache2/error.log

root@8c138884f9a3:/# tail -f /var/log/apache2/access.log

root@8c138884f9a3:/# ls -l /var/www/html

Saturday, November 16, 2019

Images, Containers and Docker Registry

This tutorial shows how to create images and containers and push to hub.docker.com registry. GitHub repo is at https://github.com/nikola-bodrozic/Docker-ReactJS

Simple Build on Linux

Apache web server no Dockerfile, $(pwd) prints path to current folder

docker run -d --name apa -e TZ=UTC -p 8080:80 -v $(pwd)/html/:/var/www/html/ ubuntu/apache2

Development Build

docker build -t reactapp:1.0 .
docker run -p 3000:3000 \ 
       --env REACT_APP_BASE_URL=localhost \ 
       --name react-app reactapp:1.0
docker logs -f YOUR_CONTAINER_SHA

Prod build & push to registry

Create empty private image repo at DOCKER_HUB_USERNAME/REPO_NAME

The repo should be visible in browser at https://hub.docker.com/repository/docker/DOCKER_HUB_USERNAME/REPO_NAME

For production you need to set env variable in Dockerfile-prod not in docker run. Here's how
RUN REACT_APP_BASE_URL=example.com yarn build

build, run and push to registry

docker run -d \
           -p 80:80 \
           --name react-app-prod DOCKER_HUB_USERNAME/REPO_NAME:1.0

docker build -t DOCKER_HUB_USERNAME/REPO_NAME:1.0 \
             -f Dockerfile-prod .

docker login

docker push DOCKER_HUB_USERNAME/REPO_NAME:1.0
DOCKER_HUB_USERNAME/REPO_NAME:1.0

Saturday, June 22, 2019

Override env. variable and shell script

Override env. variable and shell script defined in Docker file in run command.

build an image

docker build -t busybox .

run container with env. variable & run CMD in Dockerfile

docker run busybox

override env. variable in Dockerfile
docker run --env ENV_TARGET=yahoo.com busybox

override CMD in Dockerfile
docker run busybox sh -c 'whoami && pwd'

Dockerfile

FROM busybox

WORKDIR /app
ENV ENV_TARGET google.com
COPY subs.sh subs.sh
RUN chmod +x subs.sh
CMD ["/app/subs.sh"]

subs.sh

#!/bin/sh

ping -c 2 ${ENV_TARGET}

Sunday, January 6, 2019

Docker and node_modules

Development environment for a NodeJS App


Dockefile

FROM node:16-alpine

WORKDIR /app

COPY package.json ./

RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

.dockerignore

node_modules
npm-debug.log
.git
Dockerfile
.dockerignore

Open your browser on http://localhost:3000

docker-compose.yaml
version: "3.8"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - './src:/app/src'
      - './public/assets:/app/public/assets'
      - '/app/node_modules'
    ports:
      - 3000:3000
    stdin_open: true
    environment:
      - CHOKIDAR_USEPOLLING=true