DOCKER Assignment
1] Custom Docker Image
- Create a docker image and push it to docker hub & ECR
Create a Custom image
Build the custom image
docker build -t <img_name> .
Rename the image with proper git hub notation
docker tag <img_name> <new_name>
Create a repo in DockerHub & login to it using docker login command
docker login -u <user_id> -p <password>
Now push the image using "docker push"
- To push the image to ECR
Create an IAM user with necessary setup
Create a Repo in ECR
Give the necessary tag
Configure "aws ecr get-login-password"
And push the image
2] File operations
Copy a file from host machine to a running container
docker cp <source_file_path> <container_id:destination_path>
- Copy a file from running container to a host machine
docker cp <container_id>:<path_of_file> <destination_path>
3] Multi Stage Dockerfile
Write a Multi Stage Dockerfile for building and hosting a java application
Checkout the code from repository
copy the pom.xml & source code, then build a war file
Copy the war file and deploy it to a Tomcat environment
4] Docker File instructions
WORKDIR : it creates a directory and switches to that directory
USER : The USER instruction sets the user name or UID to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile
EXPOSE : it informs Docker that the container listens on the specified network ports at runtime
SHELL : it can be used more than once in a Dockerfile. All instructions that use a shell, and that come after a SHELL instruction, will use the new shell. Thus, you can change the shell multiple times in a single Dockerfile as needed
5] Jenkins Pipeline:
Create a Jenkins pipeline with the following stages;
- Checkout Stage: Checkout the source code that contains the Dockerfile.
- Build Stage: Build a Docker image using the Docker CLI.
- Push Stage: Push the image to ECR.
- Deploy Stage: Deploy the image to a Docker server as a container.
Install Jenkins
Install Docker
Install docker & docker pipeline pluggin
Give ecr-registry-full-access to ec2 instance
Create a repo in ECR
6] CGroups and Namespaces:
- Understand the concepts of CGroups and Namespaces in Linux and their relevance to Docker.
cgroups and namespaces are powerful tools for managing resources and isolating processes in Linux systems.
They play a crucial role in system administration and containerization.
Cgroups, short for control groups, allow administrators to limit and distribute resources among different groups of processes.