Docker Flashcards

1
Q

Describe a Pipeline with Docker from app build to deployment.

A
  1. Once the code is completed, you commit the code, along with the Dockerfile, to Git or any other version control system
  2. This should trigger a Continuous Integration like Jenkins Build or AWS Code Build
  3. Jenkins will build your image based on the Inst in the Dockerfile
  4. From there, push your image to a Private Docker Repo
  5. Anyone with access to the repo can pull the image to a dev server, test env or deploy it to production
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a container? (Conceptually)

A

a lightweight, standalone, executable package of software that includes everything needed to run an application from configuration to dependencies

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

Where do containers live?

A

Public Repositories like Docker Hub
Or Private Repo that can be on-prem or Cloud-based

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

How did containers improve the application Development process?

A

Containers provide an isolated environment that can install/run your pre-configured application with one command regardless of your OS

Before containers, there were a lot more steps involved in the setup. Not to mention everyone being in different env lead to inconsistencies.

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

How did containers improve the application Deployment process?

A

Now developers and Operations work together to package the application in a container.
Since all the dependencies are pre-packaged. No environmental config is needed on the server - (except for Docker Runtime)

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

What was the application Deployment process like without the use of containers?

A

The development team would produce artifacts with instructions on how to install and configure artifacts on the server. It would be up to the operations team to properly interpret instructions and set up the env to deploy the app.

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

Three main issues with deploying applications before containers?

A
  1. The Ops team might misinterpret or disagree with the Dev team’s instructions on how to install and configure artifacts on the server
  2. Which would create multiple versions of the app as they go back and forth
  3. Resulting in dependency version conflicts
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the different components that make up a container?

A

A container comprises layers of images stacked on top of each other, usually with Alpine Linux at the base.

Alpine is used since it is lightweight and small)

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

What are the requirements to pull an image from a public repo?

A

Have Docker installed locally and execute the docker run or docker pull command
No login or authentication is needed.

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

What is the advantage of containers downloading images in layers?

A

If you were to download an updated version of the image, only the layers that changed would be downloaded again. Therefore reducing the download time.

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

What is the difference between an image and a container? (image)

A

An image is the actual package made up of the application, configurations and start script. This artifact can be moved around at will and as needed.

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

What is the difference between an image and a container? (container)

A

When you pull or deploy an image and start it, that creates the container environment that contains the application and all its dependencies

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

Docker v.s. Virtual Machine?
(Size, Speed)

A

Size: Docker virtualizes the application layer, while VMs virtualize the application and OS layer. Making Docker images a couple of MB while VMs are in the GB range.
Speed: Being smaller makes Docker easier to start and run time much quicker

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

Docker v.s. Virtual Machine? (Compatibility)

A

VMs of any OS type can run on any OS host.
Docker Toolbox is needed to run on non-compatible OS’s (Older Win or Mac versions)

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

docker ps
docker ps -a

A
  1. list all running containers
  2. list all containers that are stopped and running
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What command or flag would you use with docker ps -a to only see a specific image instead of the entire list?

A

docker ps -a | grep < containername or containerID >

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

docker images

A

Will list all the images that are available (not running) on your local system.

The output will show the repo it came from, tag(version), ImageID, date created, & size

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

docker stop < container_name or container_id >

Once the container stops, you can remove it using which command?

A

To remove a Docker container, you first have to stop the running container and then delete it:

docker rm < container_name or container_id >

Remove the container w/o stopping it by using:
docker rm -f < container_name or container_id >

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

docker start < container_name or container_id >

Exp: docker start nginx-container
We can also start it as:

docker start df1c49ee5275

A

Will start a container that has already been created using docker run or the docker create command

exp: docker create –name < container_name > < image_name >

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

docker run < image_name >

A

There are docker create and start commands, but it’s a rare case to create the container and run it later.

In real-world cases, we would create and start the container in one go using the docker run command.

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

What happens if you pass docker run < image_name > to the terminal, but that image is not available locally?

A

Docker will pull the image and start the container.
If you don’t specify a version docker will always pull the latest by default.

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

Docker exposes the same port on the host machine that is exposed by the container. What is the command to bind a host port to a container port on Docker?

A

docker run –name < container_name > -d -p < host_post >:< container_port > < image_name >

docker run –name nginx-container -d -p 8080:80 nginx

23
Q

What command would you run to see the container logs?

A

docker logs < container_id or container_name >

To get the last 2 lines of the Container Logs run:
docker logs –tail 2 < container_id or container_name >

24
Q

docker exec -it < container_id or container_name >

A

the (-it) flag stand for (-i) interactive (-t) terminal. This command opens a shell inside our container that will let you navigate a directory, check env variables, and config.

Keep in mind that the containers run a lightweight version of Linux, so you wouldn’t have access to the full sweet of possible commands.

25
Q

Describe a Pipeline with Docker?

A
  1. Once the code is completed, you commit to Git or any other version control system
  2. This should trigger a Continuois Integration like Jenkins Build or AWS Code build
  3. The build tool will produce Artifacts from your application and push to a Private Docker Repo
  4. Anyone with access to the repo can pull the image to a dev server or deploy to production
26
Q

Describe a Pipeline with Docker from app build to deployment.

A
  1. Once the code is completed, you commit the code, along with the Dockerfile, to Git or any other version control system
  2. This should trigger a Continuous Integration like Jenkins Build or AWS Code Build
  3. Jenkins will build your image based on the Inst in the Dockerfile
  4. From there, push your image to a Private Docker Repo
  5. Anyone with access to the repo can pull the image to a dev server, test env or deploy it to production
27
Q

Docker Network Explained

A

Docker will automatically create an isolated Docker Network connecting containers running on the same system by just using the Container name.
Applications outside of the isolated network can connect using port #

28
Q

command to list all networks

A

docker network ls

29
Q

command to create a docker network

command to connect to a created network

A

docker network create < network name >
docker network create mongo-network

docker network connect < network_id or network_name > < container_id or container_name >

30
Q

What is the key difference between docker-compose and docker-run?

A

Docker run is a command line based
Docker-compose reads configuration data from a YAML file.

31
Q

What are the main components of a Docker Compose File?

A

version #
Services: container name and version

32
Q

Command to run/start Docker Compose File?

A

docker-compose -f < docker-compose_filename > up

exp: docker-compose -f < mongo yaml.com > down

33
Q

Command to stop all containers associated with Docker Compose File?

A

docker-compose -f < mongo yaml.com > down

34
Q

We can build a Docker image from a Dockerfile using the below command:

A

docker build -t <image_name> <context_dir></context_dir></image_name>

35
Q

Define a Dockerfile?

A

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

36
Q

What is the first step in creating a Dockerfile?

A

A Dockerfile must begin with a FROM < imagename >
The FROM instruction specifies the Parent Image from which you are building your image

37
Q

What must the dockerfile always be named?

A

Dockerfile with a capital D saved in the same directory as your application

38
Q

What does the RUN command do in a dockerfile?

A

This command allows you to execute and Linux Command
Exp: RUN mkdir -p /home/app
In the above example, that directory will be created inside the container

39
Q

What does the COPY command do in a dockerfile?

A

The COPY command executes on the host. It serves the purpose of copying your source code from your host into your container
Exp: COPY . /home/app

40
Q

What does the CMD command do in a dockerfile?

A

CMD executes an entry point Linux command.

41
Q

ENTRYPOINT and CMD are essential for building and running Dockerfiles—it simply depends on your use case.

As a general rule of thumb opt for ENTRYPOINT instructions when building an

A

executable Docker image using commands that always need to be executed.

42
Q

ENTRYPOINT and CMD are essential for building and running Dockerfiles—it simply depends on your use case. As a general rule of thumb, CMD instructions are best for an

A

CMD instructions are best for an additional set of arguments that act as default instructions till there is an explicit command line usage when a Docker container runs.

43
Q

What is the command to build an image once a Dockerfile has been created?

A

docker build -t < image_name: version# > < location_of_Dockerfile >

44
Q

How do you implement a change made to a Dockerfile?

A

If you adjust a Dockerfile, you **MUST rebuild the image ** due to the old image not being able to be overwritten.

45
Q

What is the command to delete and image?

A

docker rmi < container_name or container_id >

46
Q

After containerizing your image and pushing it to a Private Repo, what change would you have to make to your Docker-compose.YAML file before you can start the application on a deployment server.

A

You would have to add the Docker-compose.YAML file on your deployment server. And update it with the
path information needed to pull and configure your
containerized application from the private repo.

The Docker-compose.YAML file has the config instructions for all the containers that make up the application.

47
Q

What are the steps to adding the containerized image of your application to your Docker-compose.YAML file?

A

Under services in your Docker-compose.YAML you have to add:
services:
my-app: (container_name)
image: < path to your image in private repo >
ports:
- :3000:3000

48
Q

What are Docker Volumes?

A

Docker volumes are used to persist data from within a Docker container. Otherwise all data would be lost after every stop.

49
Q

There are a few different types of Docker volumes:

A

host, anonymous, and, named.

50
Q

A host volume can be accessed from

A

A host volume can be accessed from within a Docker container and is stored on the host, as per the name. To create a host volume, run:

51
Q

When to use a host volume?

A

Use a host volume when you need to know where to refer to the data. It’s also the easiest type of volume to use, so it’s ideal for simple projects.

52
Q

Anonymous volumes: The location of anonymous volumes is managed by Docker. Why are they not used as often?

A

It can be difficult to refer to the same volume when it is anonymous. Anonymous volumes provide flexibility, but they aren’t used as often now that named volumes have been introduced.

53
Q

Named volumes and anonymous volumes are similar in that Docker

A

manages where they are located.

Named volumes provide flexibility, but they are also explicit. This makes them easier to manage.