Part of an Image
Could be Files or Command
Image of a "Container"
Consists of multiple Layers
Instanced version of an Image
Many Containers can run the same Image
# Use the official image as a parent image.
FROM node:current-slim
# Set the working directory.
WORKDIR /usr/src/app
# Copy the file from your host to your current location.
COPY package.json .
# Run the command inside your image filesystem.
RUN npm install
# Add metadata to the image to describe which port the container is listening on at runtime.
EXPOSE 8080
# Run the specified command within the container.
CMD [ "npm", "start" ]
# Copy the rest of your app's source code from your host to your image filesystem.
COPY . .
Service to administrate Images
Biggest One : Docker Hub
Mostly folder(s) on the Host System
Volumes are "mounted" into a Container
Connection to the "outer" World could be Local or on the Internet
The Container uses the Host's Connection and Adapter
VM or physical Machine, which is a member of a Network
# Filename: Dockerfile.build
FROM node:10-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
docker-compose up
and Compose starts and runs your entire app.
FROM node:6
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm cache clean
RUN npm install
COPY . /usr/src/app
EXPOSE 4200
CMD ["npm","start"]
FROM node:6
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm cache clean
RUN npm install
COPY . /usr/src/app
EXPOSE 3000
CMD ["npm","start"]
# Define the services/ containers to be run
services:
#######################
angular:
build: angular-app
ports:
- "4200:4200"
#######################
express:
build: express-server
ports:
- "3000:3000"
links:
- database
#######################
database:
image: mongo
ports:
- "27017:27017"
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
/etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
sudo systemctl start jenkins
docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
docker network create jenkins
docker image pull docker:dind
docker run \
--name jenkins-docker \
--privileged \
--network jenkins
--network-alias docker \
--env DOCKER_TLS_CERTDIR=/certs \
--volume jenkins-docker-certs:/certs/client \
--volume jenkins-data:/var/jenkins_home \
--publish 2376:2376 \
docker:dind
FROM jenkins/jenkins:2.249.3-slim
USER root
RUN apt-get update && apt-get install -y apt-transport-https \
ca-certificates curl gnupg2 \
software-properties-common
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable"
RUN apt-get update && apt-get install -y docker-ce-cli
USER jenkins
RUN jenkins-plugin-cli --plugins blueocean:1.24.3
docker build -t my-docker-jenkins-image .
docker run my-docker-jenkins-image
export REPO_NAME='Mueller-Patrick/Betterzon'
export JOB_NAME='Verify_Build_on_PR'
curl "https://api.GitHub.com/repos/$REPO_NAME/statuses/$GIT_COMMIT" \
-H "Content-Type: application/json" \
-H "Authorization: token $GH_TOKEN" \
-X POST \
-d "{
\"state\": \"pending\",
\"context\": \"jenkins/$REPO_NAME\",
\"description\": \"Jenkins\",
\"target_url\": \"https://ci.betterzon.xyz/job/$JOB_NAME/$BUILD_NUMBER/console\"
}"
export REPO_NAME='Mueller-Patrick/Betterzon'
export JOB_NAME='Verify_Build_on_PR'
TEST_ERROR=0
cd Frontend
ng build || TEST_ERROR=$?
cd ..
if [ $TEST_ERROR -eq 0 ] ; then
curl "https://api.GitHub.com/repos/$REPO_NAME/statuses/$GIT_COMMIT" \
-H "Content-Type: application/json" \
-H "Authorization: token $GH_TOKEN" \
-X POST \
-d "{
\"state\": \"success\",
\"context\": \"jenkins/$REPO_NAME\",
\"description\": \"Jenkins\",
\"target_url\": \"https://ci.betterzon.xyz/job/$JOB_NAME/$BUILD_NUMBER/console\"
}"
else
curl "https://api.GitHub.com/repos/$REPO_NAME/statuses/$GIT_COMMIT" \
-H "Content-Type: application/json" \
-H "Authorization: token $GH_TOKEN" \
-X POST \
-d "{
\"state\": \"failure\",
\"context\": \"jenkins/$REPO_NAME\",
\"description\": \"Jenkins\",
\"target_url\": \"https://ci.betterzon.xyz/job/$JOB_NAME/$BUILD_NUMBER/console\"
}"
exit $TEST_ERROR
fi
FROM jenkins/jenkins:latest
RUN /usr/local/bin/install-plugins.sh git matrix-auth workflow-aggregator docker-workflow blueocean credentials-binding
ENV JENKINS_USER admin
ENV JENKINS_PASS admin
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false
COPY executors.groovy /usr/share/jenkins/ref/init.groovy.d/
COPY default-user.groovy /usr/share/jenkins/ref/init.groovy.d/
VOLUME /var/jenkins_home
FROM ubuntu:16.04
# Install Docker CLI in the agent
RUN apt-get update && apt-get install -y apt-transport-https ca-certificates
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
RUN echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" > /etc/apt/sources.list.d/docker.list
RUN apt-get update && apt-get install -y docker-ce --allow-unauthenticated
RUN apt-get update && apt-get install -y openjdk-8-jre curl python python-pip git
RUN easy_install jenkins-webapi
# Get docker-compose in the agent container
.
.
.
.
version: '3.1'
services:
jenkins:
build: jenkins-master
container_name: jenkins
ports:
- '8080:8080'
- '50000:50000'
jenkins-slave:
build: jenkins-slave
container_name: jenkins-slave
restart: always
environment:
- 'JENKINS_URL=http://jenkins:8080'
volumes:
- /var/run/docker.sock:/var/run/docker.sock # Expose the docker daemon in the container
- /home/jenkins:/home/jenkins # Avoid mysql volume mount issue
depends_on:
- jenkins