Linux+ Container Operations with Docker Flashcards
6 cards from real Linux practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Linux+ Container Operations with Docker flashcards as text
A Linux administrator is performing maintenance on a Docker host and needs to reclaim disk space. Which command should they use to remove all unused images, including tagged images that are not associated with any container?
Answer: docker image prune -a
The `docker image prune` command is used to remove unused images. By default, it only removes dangling images (those without a tag). The `-a` (or `--all`) flag extends this to remove all images that are not associated with at least one container, which is what the scenario requires.
Which of the following commands will start a new container from the `ubuntu:latest` image, name it `my-test-container`, and ensure it runs in the background as a daemon?
Answer: docker run -d --name my-test-container ubuntu:latest
The `docker run` command creates and starts a new container. The `-d` flag runs the container in detached mode (in the background), and the `--name` flag assigns a user-friendly name to it.
A developer needs to deploy a database in a Docker container. It is critical that the database's data persists even if the container is removed. Which command correctly maps a Docker-managed named volume called `db_data` to the `/var/lib/mysql` directory inside the container?
Answer: docker run -d --mount type=volume,source=db_data,target=/var/lib/mysql mysql
To persist data using a Docker-managed named volume, the `--mount` flag is recommended for its clarity. The syntax `type=volume,source=db_data,target=/var/lib/mysql` explicitly creates (if not existing) a named volume called `db_data` and maps it to the `/var/lib/mysql` directory inside the container. This ensures data persists independently of the container's lifecycle.
An administrator is troubleshooting a network connectivity issue with a running container named `api-gateway`. Which command would they use to view detailed configuration information about the container, including its assigned IP address, mounts, and port mappings?
Answer: docker inspect api-gateway
The `docker inspect` command provides low-level, detailed information on Docker objects. When run against a container, it returns a JSON array containing its complete configuration, including network settings like the IP address, volume mounts, and environment variables.
A developer has created a web application that listens on port 3000 inside its container. To make this application accessible on port 80 on the host machine, which `docker run` flag and argument should be used?
Answer: -p 80:3000
The `-p` or `--publish` flag is used to map a host port to a container port. The format is `HOST_PORT:CONTAINER_PORT`. Therefore, to map port 80 on the host to port 3000 inside the container, the correct syntax is `-p 80:3000`.
When building a Docker image with a Dockerfile, which instruction specifies the default command to be executed when a container is started, and is designed to be easily overridden by providing arguments to the `docker run` command?
Answer: CMD
The `CMD` instruction sets the default command and/or parameters for a container. These can be overridden simply by specifying a different command after the image name in a `docker run` command. `RUN` executes commands during the image build, and `ENTRYPOINT` configures the container to run as an executable, making it harder to override.