2. Develop with Docker Flashcards

1
Q

What is Docker Compose?

A

A tool for defining and running multi-container Docker applications, which uses a YAML file to configure the application’s services.

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

How do you configure Docker Compose?

A

By using a YAML file name docker-compose.yml.

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

What does the Docker Compose config file do?

A

It allows us to specify what services we want to compose using Docker Compose, as well as their configurations.

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

How do you define your services using a Docker Compose config file?

A

By using the services key.

eg.

services:
myapp …
mongo …
~~~
~~~

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

How do you define the container name for a service to run using a Docker Compose config file?

A

By using the container_name key.

eg.

services:
myapp:
container_name: myapp

~~~
~~~

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

How do you define the configuration options to be applied at build time for a service using a Docker Compose config file?

A

By using the build key.

build can be specified either as a string containing a path to the build context or as an object with the path specified under context and optionally Dockerfile and args.

eg.

services:
myapp:
build: path/to/context
~~~
OR
~~~
services:
myapp:
build:
context: path/to/context
~~~
~~~

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

What is a restart policy, and how do you define it for a service, using a Docker Compose config file?

A

It’s an object that configures if and how to restart containers when they exit. It is defined by using the restart_policy key for service.

eg.

services:
myapp:
restart_policy:

~~~
~~~

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

How do you specify a restart policy condition using a Docker Compose config file?

A

Inside a service object, either by passing the condition to the restart key, or specifying using condition key within a restart_policy object.

eg.

services:
myapp:
restart: always
~~~
OR
~~~
services:
myapp:
restart_policy:
condition: always
~~~
~~~

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

How do you expose a port to the host machine for a service using a Docker Compose config file?

A

Inside a service object, by using the ports key with either an array of simple single values or objects.

eg.

services:
myapp:
ports:
- “8000:8000”
- …
~~~
OR
~~~
services:
myapp:
ports:
- target: 80
published: 8080
protocol: tcp
mode: host
- …
~~~
~~~

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

How do you specify a link to another service for a given service using a Docker Compose config file?

A

Using the links key inside the service object and specifying an array of service names or of service name and alias combinations each separated by a column.

eg.

services:
myapp:
links:
- mongo
# OR
- mongo:database
~~~
~~~

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

How do you mount host paths or named volumes for a service?

A

By using the volumes key inside the service object and specifying an array of source and destination path combinations each separated by columns.

eg.

services:
myapp:
volumes:
# Specify a path and let the Engine create volume:
- /var/lib/mysql
# Specify an absolute path mapping:
- /opt/data:/var/lib/mysql
# Path on the host, relative to the Compose file:
- ./cache:/tmp/cache
# User-relative path:
- ~/configs:/etc/configs/:to
# Named volume:
- datavolume:/var/lib/mysql
~~~
~~~

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

How do you specify the ports to be exposed to linked services without publishing them to the host machine for a given system using the Docker Compose config file?

A

By using the expose key within the service object and specifying an array of ports to be exposed.

eg. ```
services:
    myapp:
         links: 
           expose:
               - "8000"

~~~

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

How do you specify the image to start the container from using either a repository/tag or a partial image ID in the docker-compose file?

A

By using the image keyword and specifying the repository/tag or the partial image ID.

eg. ```
services:
    myapp:
         image: mongo 

~~~

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

How do you build your services specified in the docker-compose file?

A

By executing the docker-compose build command inside the folder where the docker-compose file is.

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

How do you create and start the associated containers for the services you specified in the docker-compose file?

A

By executing the docker-compose up command inside the folder where the docker-compose file is.

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

How do you print the logs for a Docker container on the command line?

A

By using the docker logs command with the container id or name.

eg. docker logs myapp

17
Q

How do you create and start the associated container for a given service that you specified in the docker-compose file?

A

By executing the docker-compose up command with the -d flag and the service name.

eg. docker compose up -d myapp

18
Q

How do you stop the services that are specified in the docker-compose file?

A

By executing the docker-compose down or docker-compose stop command.

19
Q

How do you remove a docker image?

A

By using the docker rmi command with the image ID or name.

eg. docker rmi alicandemirtas/simple-frontend

20
Q

How do you pull an image from DockerHub?

A

By using the docker pull command with the image name or id.

21
Q

How do you push an image to DockerHub?

A

By using the docker push command with the image name or id.

22
Q

Express dependency between services in a docker-compose file?

A

By using the depends_on keyword end specifying the name of the depended-on service.

eg. ```
services:
    myapp:
         depends_on: mongo 

~~~