21 - DOCKER Flashcards

1
Q

How do we isolate services

A

Install applications on different virtual servers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why we isolate services

A

To archieve high availability
High performance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

cons of VM

A

o Expenditure
o Compute resources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is a container

A

A standard unit of software that packages up code, dependencies for development, shipment and deployment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

container vs VM

A

Container offer isolation not virtualization
Containers are OS virtualization
VM’s are hardware virtualization
VM’s needs OS
Containers don’t need OS
Containers uses host OS for compute resource

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is docker

A

Docker is a container runtime environment, manages containers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

advantages of docker

A

Standard and portable
Lightweight
secure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

docker installation and setup on linux VM

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

add user to docker group

A

sudo vim /etc/group
docker: x :999:ubuntu
$ usermod -aG ubuntu

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

enable docker start on boot

A

sudo systemctl enable docker

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Install hello-world image

A

docker run hello-world

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is dockerhub

A

Registry for docker images

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

describe a docker image

A

o A stopped container like vm image
o Consist of multiple layers
o An app will be bundled in an image
o Containers run from images
o Images are called repositories in registries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

popular docker registries

A

ECR, GCR, dockerhub

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

command to create/run a container

A

docker run [image-name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

command to view docker images locally

A

docker images

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Get image locally

A

docker pull image_name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

run container with name in detached mode

A

docker run –name myweb -d nginx -p [host port]: [container port]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

list running containers

A

docker ps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

list all containers

A

docker ps -a

21
Q

stop/start a container

A

docker stop/start [container_id]

22
Q

view container details

A

du -sh [container_id]

23
Q

run command into container

A

docker exec myweb /bin/bash
docker exec -it myweb /bin/bash

24
Q

remove image

A

docker rmi nginx

25
remove container
docker rm [id]
26
view low-level docker logs
docker inspect
27
view docker logs
docker logs container_name
28
run mysql container
docker run -d -P -e MYSQL_ROOT_PASSWORD=mypass mysql:5.7
29
docker persistent data options
volumes and bind mounts
30
sample command for mysql bind mount
docker run - - name vprodb -d -e MYSQL_ROOT_PASSWORD=secretpass -p 3030:3306 -v /home/ubuntu/vprodbdata:/var/lib/mysql mysql:5.7
31
create docker volume
docker volume create mydbdata
32
what is a docker volume
host machine reference for container storage
33
create docker mysql volume mount
docker run - - name vprodb -d -e MYSQL_ROOT_PASSWORD=secretpass -p 3030:3306 -v mydbdata:/var/lib/mysql mysql:5.7
34
view volume content
ls /var/lib/docker/volumes/mydbdata
35
what is a dockerfile
36
sample dockerfile
o FROM o LABELS o RUN o ADD/COPY o CMD o ENTRYPOINT o VOLUME o EXPOSE o ENV o USER o WORKDIR o ARG o ONBUILD
37
o Write dockerfile Image, author, project, install git, install apache2 Start apache in foreground Port 80 Noninteractive environment Specify working dir Create a volume location Add nano.tar to webserver location Build image Run container Host image to dockerhub Remove images and containers Run container from dockerhub
Use an official base image FROM ubuntu:20.04 Set author metadata LABEL author="Your Name" LABEL project="Your Project" Install required packages (git, apache2) and clean up apt cache RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y git apache2 && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* Start Apache in the foreground CMD ["apache2ctl", "-D", "FOREGROUND"] Expose port 80 EXPOSE 80 Set noninteractive environment ENV DEBIAN_FRONTEND=noninteractive Specify working directory WORKDIR /var/www/html Create a volume location VOLUME /var/www/html Copy nano.tar to the webserver location COPY nano.tar /var/www/html Build image using: docker build -t my-apache-image . # Run container using: docker run -d -p 8080:80 --name my-apache-container my-apache-image
38
usage of CMD
CMD [command, argument]
39
usage of ENTRYPOINT
ENTRYPOINT [command] # receives command and argument via the command line
40
usage of CMD/ENTRYPOINT
ENTRYPOINT [command] CMD [argument]
41
what is docker-compose
Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define an entire application stack, including services, networks, and volumes, in a single YAML file called a docker-compose.yml file. With Docker Compose, you can manage complex, multi-container applications more efficiently by simplifying the process of defining, configuring, and deploying them.
42
docker-compose installation
run curl command make executable
43
getting started guide
https://docs.docker.com/compose/gettingstarted/
44
build and run containers with docker-compose
docker compose up
45
what is a multistage dockerfile?
A multi-stage Dockerfile is a Dockerfile that uses multiple build stages to create a final Docker image. This technique is especially useful for creating smaller and more efficient Docker images by separating the build and runtime environments. Multi-stage builds allow you to include only the necessary files and dependencies in the final image, discarding unnecessary build tools and artifacts.
46
sample multistage dockerfile
47
48