Giter Club home page Giter Club logo

container-build's Introduction

Container build examples

OpenShift docker / container Build examples

Simple Docker build (Dockerfile)

cd simple-docker-build/
docker build -t simple-docker-build:latest -f Dockerfile .
docker run -ti -p 8080:8080 --rm simple-docker-build:latest

OpenShift BuildConfig

oc create is simple-docker-build

oc apply -f - <<EOF
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: simple-docker-build
  labels:
    name: simple-docker-build
spec:
  triggers:
    - type: ConfigChange
  source:
    contextDir: "simple-docker-build/"
    type: Git
    git:
      uri: 'https://github.com/openshift-examples/container-build.git'
  strategy:
    type: Docker
  output:
    to:
      kind: ImageStreamTag
      name: 'simple-docker-build:latest'
EOF

Simple Container build (Containerfile)

cd simple-container-build/
docker build -t simple-container-build:latest -f Containerfile .
docker run -ti -p 8080:8080 --rm simple-container-build:latest

OpenShift BuildConfig

oc create is simple-container-build

oc apply -f - <<EOF
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: simple-container-build
  labels:
    name: simple-container-build
spec:
  triggers:
    - type: ConfigChange
  source:
    contextDir: "simple-container-build/"
    type: Git
    git:
      uri: 'https://github.com/openshift-examples/container-build.git'
  strategy:
    type: Docker
    dockerStrategy:
      dockerfilePath: "Containerfile"
  output:
    to:
      kind: ImageStreamTag
      name: 'simple-container-build:latest'
EOF

Simple context dir (Containerfile)

cd simple-context-dir/
docker build -t simple-context-dir:latest -f Containerfile .
docker run -ti -p 8080:8080 --rm simple-context-dir:latest

OpenShift BuildConfig

oc create is simple-context-dir

oc apply -f - <<EOF
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: simple-context-dir
  labels:
    name: simple-context-dir
spec:
  triggers:
    - type: ConfigChange
  source:
    contextDir: "simple-context-dir/"
    type: Git
    git:
      uri: 'https://github.com/openshift-examples/container-build.git'
  strategy:
    type: Docker
    dockerStrategy:
      dockerfilePath: "Containerfile"
  output:
    to:
      kind: ImageStreamTag
      name: 'simple-context-dir:latest'
EOF

Complex context dir (Containerfile)

cd complex-context-dir/
docker build -t complex-context-dir:latest -f containerfiles/Containerfile .
docker run -ti -p 8080:8080 --rm complex-context-dir:latest

OpenShift BuildConfig

oc create is complex-context-dir

oc apply -f - <<EOF
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: complex-context-dir
  labels:
    name: complex-context-dir
spec:
  triggers:
    - type: ConfigChange
  source:
    contextDir: "complex-context-dir/"
    type: Git
    git:
      uri: 'https://github.com/openshift-examples/container-build.git'
  strategy:
    type: Docker
    dockerStrategy:
      dockerfilePath: "containerfiles/Containerfile"
  output:
    to:
      kind: ImageStreamTag
      name: 'complex-context-dir:latest'
EOF

Multi-stage build (Containerfile)

cd multi-stage/
docker build -t multi-stage:latest -f containerfiles/Containerfile .
docker run -ti -p 8080:8080 --rm multi-stage:latest

OpenShift BuildConfig

oc create is multi-stage

oc apply -f - <<EOF
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  name: multi-stage
  labels:
    name: multi-stage
spec:
  triggers:
    - type: ConfigChange
  source:
    contextDir: "multi-stage/"
    type: Git
    git:
      uri: 'https://github.com/openshift-examples/container-build.git'
  strategy:
    type: Docker
    dockerStrategy:
      dockerfilePath: "Containerfile"
  output:
    to:
      kind: ImageStreamTag
      name: 'multi-stage:latest'
EOF

Entitled build (Containerfile)

oc create secret generic etc-pki-entitlement \
    --from-file /etc/pki/entitlement/xxxxxx.pem \
    --from-file /etc/pki/entitlement/xxxxxx-key.pem 

oc import-image rhel7:7.6 \
  --from=registry.access.redhat.com/rhel7/rhel:7.6  \
  --namespace openshift \
  --confirm

oc create is own-apache-container-rhel7

# Create imagestream own-apache-container-rhel7 
oc create is own-apache-container-rhel7

oc apply -f - <<EOF
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
  annotations:
    openshift.io/generated-by: OpenShiftNewBuild
  creationTimestamp: null
  labels:
    build: own-apache-container-rhel7
  name: own-apache-container-rhel7
spec:
  nodeSelector: null
  output:
    to:
      kind: ImageStreamTag
      name: own-apache-container-rhel7:latest
  postCommit: {}
  resources: {}
  source:
    git:
      uri: https://github.com/openshift-examples/own-apache-container.git
    type: Git
    # IMPORTANT: mount the rhel entitlement
    secrets:
    - secret:
        name: etc-pki-entitlement
      destinationDir: etc-pki-entitlement
  strategy:
    dockerStrategy:
      # IMPORTANT: to select the rhel dockerfile
      dockerfilePath: Dockerfile.rhel
      from:
        kind: ImageStreamTag
        name: rhel7:7.6
        namespace: openshift
    type: Docker
  triggers:
  - type: ConfigChange
  - imageChange: {}
    type: ImageChange
status:
  lastVersion: 0
EOF

container-build's People

Contributors

rbo avatar nsu700 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.