-
Docker is an open-source engine that automates the deployment of applications into containers
-
Written by the team at Docker, Inc
-
You can get started with Docker on a minimal host running nothing but a compatible Linux kernel and a Docker binary.
-
To run on Windows and Mac, you have to install Boot2Docker.
-
Aims to make your applications portable, easy to build, and easy to collaborate on.
-
Docker client (Docker binary you install and run commands using it)
-
Docker server (Docker daemon )
-
Registries (Storage media of your Docker images)
-
Docker Containers (Instances of your Docker images)
-
Images are the building blocks of the Docker world
-
You launch your containers from images.
-
They are a layered format, using Union file systems, that are built step-by-step using a series of instructions.
-
Example of how a docker image is build from instaructions :
1. Add a file
2. Run a command
3. Open a port
- They are highly portable and can be shared, stored, and updated.
-
Docker stores the images you build in registries.
-
Two types of registries:
-
Public (like DockerHub)
-
Private
-
-
Images live inside repositories, and repositories live on registries. The default registry is the public registry managed by Docker, Inc., Docker Hub.
-
Containers are launched from images and can contain one or more running processes.
-
Docker borrows the concept of the standard shipping container, used to transport goods globally, as a model for its containers. But instead of shipping goods, Docker containers ship software.
docker run -i -t --rm -v /etc/yum.conf:/etc/yum.conf --name my_centos_container centos:7 /bin/bash
Now run following commands inside this container,
root@<container_id>:/# hostname
root@<container_id>:/# ls
root@<container_id>:/# yum install -y vim
docker images
- These local images live on our local Docker host in the
/var/lib/docker
directory.
docker ps
docker ps
docker logs <container_name>
- Use
-f
to tail logs
docker top <container_name>
docker inspect <container_name>
docker rm <container_name>
- use
-f
to force remove
- Images can be layered on top of one another.
- The image below is called the parent image and you can traverse each layer until you reach the bottom of the image stack where the final image is called the base image.
- Finally, when a container is launched from an image.
- Docker mounts a read-write filesystem on top of any layers below. This is where whatever processes we want our Docker container to run will execute.
docker serach <image_name>
- You can also browse the available images online at Docker Hub.
Example:
# Seach for an image
docker search prateekjoshi
# Pull the image
docker pull prateekjoshi/spring-mvc-app
-
Two methods to build your own images:
-
Using
docker commit
command -
Using
docker build
command with a Dockerfile
-
-
NOTE :The docker commit method is not currently recommended, as building with a Dockerfile is far more flexible and powerful.
- Run a container from parent image
docker run -i -t debian:jessie /bin/bash
- Do some changes on the running container
mkdir app_config
cd app_config
touch app.conf
-
Exit from the container using
exit
command -
Now, we will create an image containing our app configuration files
docker commit <container_id> <name_of_image_to_create>
- Run an instance of this new image created and verify the changes
docker run --name <container_name> -i -t <new_image_created> /bin/bash
-
Create a sample Dockerfile
FROM ubuntu:14.04
MAINTAINER Prateek Joshi "prateek@xyz.com"
RUN apt-get update
RUN apt-get install -y sysvbanner
ENTRYPOINT ["banner"]
CMD ["Prateek"]
-
Build your image using
docker build
command
docker build --build-arg http_proxy=http://$http_proxy --build-arg https_proxy=http://$https_proxy -t banner_image .
- Run a container from the image you just created
docker run --name <container_name> <image_name> "DOCKER"
1.Create a volume to mount which will hold your Jenkins data.
mkdir jenkins_data
cd jenkins_data
2.Install and run Jenkins under Docker Container
docker run --name <container_name> -u root --rm -p 8080:8080 -p 50000:50000 -v `pwd`:/var/jenkins_home jenkins:latest
3.Stop Jenkins container
docker stop <container_name>
4.Run a new instance of Jenkins container using same jenkins_data
volume.
docker run --name <container_name> -u root --rm -p 8080:8080 -p 50000:50000 -v `pwd`:/var/jenkins_home jenkins:latest
5.We can see that we have a PORTABLE and SCALABLE jenkins server which can easily be backed up.
1.Clone the git repo
git clone https://github.com/PrateekJoshi/spring-mvc-app
2.Building the web app
./build.sh
3.Running the web app isnide a Docker container
`./run.sh