Docker 测试

Docker Multiple-Choice Questions

1. Why is Docker useful in software development?

A) It eliminates the need for a server
B) It creates a standardized environment across different machines
C) It replaces the need for Python
D) It automatically fixes application crashes

2. How does Docker differ from a Virtual Machine?

A) Docker runs on a separate operating system while VMs share the host OS
B) Docker containers take up more space than VMs
C) Docker uses containers within an existing OS, whereas VMs simulate a whole OS
D) Docker requires cloud services, but VMs do not

3. What is the purpose of a Dockerfile?

A) To define how to run Docker containers
B) To store environment variables
C) To manage Docker networking
D) To configure system hardware

4. In the provided Dockerfile, what does FROM python:3 do?

A) Creates a new Python package
B) Specifies that the container is running Python 3
C) Installs Python 3 from a local file
D) Runs a Python script

5. What does the CMD instruction in a Dockerfile specify?

A) The base image to use
B) The command to run when the container starts
C) A list of environment variables
D) A list of dependencies to install

6. In the command COPY . /usr/src/app, what does . represent?

A) The container’s root directory
B) The current directory on the host machine
C) A wildcard for all files in the system
D) The Python package directory

7. What is the purpose of docker-compose.yml?

A) To build and manage multiple containers together
B) To replace the need for a Dockerfile
C) To install dependencies within a container
D) To list all available containers on a machine

8. In docker-compose.yml, what is the function of volumes?

A) It stores logs generated by the container
B) It links directories between the host and the container
C) It specifies the network settings of the container
D) It determines the database version used

9. What does docker-compose up do?

A) Builds and starts the services defined in docker-compose.yml
B) Deletes all running containers
C) Installs required dependencies in the container
D) Stops all running containers

10. What is the command to list all running Docker containers?

A) docker images
B) docker ps
C) docker start
D) docker ls

11. What does docker exec -it CONTAINER_ID bash -l do?

A) Lists all running Docker containers
B) Enters the specified running container’s shell
C) Stops a running Docker container
D) Deletes a container

12. How do you exit an interactive session inside a Docker container?

A) docker stop
B) CTRL+C
C) CTRL+D
D) docker kill


Answers and Explanations

  1. B – Docker ensures that applications run in a consistent environment across different machines.
  2. C – Unlike VMs, Docker containers share the host OS kernel and consume fewer resources.
  3. A – A Dockerfile defines the setup and execution of a Docker container.
  4. B – The FROM instruction selects a base image with Python 3 pre-installed.
  5. B – The CMD command specifies what to run when the container starts.
  6. B – The dot (.) represents the current working directory on the host machine.
  7. Adocker-compose.yml helps define and manage multiple services (containers).
  8. Bvolumes link directories between the host and the container for persistent storage.
  9. Adocker-compose up starts and builds services as defined in docker-compose.yml.
  10. Bdocker ps lists all running Docker containers.
  11. B – This command enters an interactive shell inside the specified container.
  12. CCTRL+D exits an interactive shell session inside a Docker container.

Summary of Key Docker Concepts

  • Purpose of Docker: Ensures applications run in a consistent environment across different systems.
  • Containers vs. VMs: Containers share the host OS, making them lightweight; VMs run a full OS.
  • Dockerfile: A script defining how a container should be built and run.
  • Key Dockerfile Commands:
    • FROM selects a base image.
    • COPY transfers files from the host to the container.
    • WORKDIR sets the working directory.
    • RUN executes setup commands.
    • CMD specifies the startup command.
  • Docker Compose: Manages multiple containers, defined in docker-compose.yml.
  • Key Commands:
    • docker-compose up: Starts all services.
    • docker ps: Lists running containers.
    • docker exec -it CONTAINER_ID bash -l: Enters a container shell.
    • CTRL+D: Exits a container session.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值