DevSecOps for BBK
  • Introduction
  • Getting Started
    • Virtual Training Practices
    • Training Plan
    • Tools and Configuration
    • Troubleshooting
  • Docker Fundamentals
    • Docker Setup
    • Docker First Container
    • Docker Network Basics
    • Docker Network Exercise
    • Docker Volume Basics
    • Docker Storage
  • Dockerfile Fundamentals
    • Dockerfile Instructions
    • Dockerfile Environment Variables
    • Dockerfile Build Arguments
    • Non-privileged Containers
    • Dockerfile Order of Execution
    • Dockerfile Volume
    • Entrypoint Command
    • Multiple Stage Build
  • Container Management
    • Containers Start Automatically
  • Docker Security
    • Seccomp Profile
  • Docker Compose
    • Docker Compose Install
    • Docker Compose Commands
    • Docker Compose File
    • Docker Compose Volumes and Network
  • K8s Cluster Setup
    • Minikube Installation
    • Calico Networking
    • K8s Walkthrough
    • K8s Cheat Sheet
  • Understand K8s
    • Pod Connectivity
    • Deployments
    • Service Cluster IP
    • Service NodePort
    • ClusterIP Exercise
    • NodePort Exercise
    • Service LoadBalancer
    • Configmap
    • Secrets
  • Application Lifecycle Management
    • Rolling Updates and Rollback
    • Multi Container Pod
  • K8s Storage
    • Persistent Volume
    • Persistent Volume Claim
    • PVC in POD
  • Istio
    • AKS Setup
    • Kubectl Setup in Windows
    • Istio Setup Manual
    • Istio Demo App
    • Istio Observability
  • Terraform
    • Terraform Setup
    • Terraform Demo
    • Azure Terraform Setup
  • Terraform AWS
    • Terraform AWS Setup
    • Terraform AWS Demo S3
  • Refrences
    • Docker Static Site
    • Docker First Image
Powered by GitBook
On this page
  • Dockerfile Environment Variables
  • Setup your environment:
  • Create an image for the weather-app
  1. Dockerfile Fundamentals

Dockerfile Environment Variables

Dockerfile Environment Variables

To make new software easier to run, you can use ENV to update the PATH environment variable for the software that your container installs.

Setup your environment:

Step 1: Make the env Directory

mkdir env
cd env

Use the --env flag to pass an environment variable when building an image:

--env [KEY]=[VALUE]

Use the ENV instruction in the Dockerfile:

ENV [KEY]=[VALUE] ENV [KEY] [VALUE]

Step 1: Clone the weather-app:

git clone https://github.com/nishanthkumarpathi/content-weather-app.git src

Step 2: Create the Dockerfile

vi Dockerfile

Create an image for the weather-app

Step 3: Dockerfile contents:

FROM node
LABEL org.label-schema.version=v1.1
ENV NODE_ENV="development"
ENV PORT 3000

RUN mkdir -p /var/node
ADD src/ /var/node/
WORKDIR /var/node
RUN npm install
EXPOSE $PORT
CMD ./bin/www

Step 4: Create the weather-app container:

docker image build -t nishanthkp/weather-app:v2 .

Step 5: Inspect the container to see the environment variables:

docker image inspect nishanthkp/weather-app:v2

Step 6: Deploy the weather-dev application:

docker container run -d --name weather-dev -p 8082:3001 --env PORT=3001 nishanthkp/weather-app:v2

Step 7: Inspect the development container to see the environment variables:

docker container inspect weather-dev

Step 8: Deploy the weather-app to production:

docker container run -d --name weather-app2 -p 8083:3001 --env PORT=3001 --env NODE_ENV=production nishanthkp/weather-app:v2

Step 9: Inspect the production container to see the environment variables:

docker container inspect weather-app2

Step 10: Get the logs for weather-app2:

docker container logs weather-app2
docker container run -d --name weather-prod -p 8084:3000 --env NODE_ENV=production nishanthkp/weather-app:v2
PreviousDockerfile InstructionsNextDockerfile Build Arguments

Last updated 2 years ago