Here are 10 sample questions related to container management, similar to the one
you provided. These questions will help you practice various aspects of managing
containers:
### Sample Questions:
1. Container Creation:
- Create a container named `webapp` using the `nginx` image from
`registry.example.com`. Set up port forwarding so that port `8080` on the host maps
to port `80` in the container.
ans: #podman run -d --name webapp -p 8080:80 registry.example.com/nginx
2. Persistent Storage:
- Create a container `database` using the `mysql` image. Mount the host
directory `/data/mysql` to `/var/lib/mysql` inside the container. Ensure that the
data persists even if the container is removed.
3. Systemd Integration:
- Create a container `myapp` from the `myapp_image` and configure a `systemd`
service named `myapp-container` to automatically start the container upon reboot
for the user `student`.
4. Logging:
- Configure a container named `log-collector` using `fluentd` image to collect
logs from `/var/log/nginx` on the host system. Mount the directory to `/mnt/logs`
inside the container.
5. Container Networking:
- Create a user-defined network named `mynetwork` and connect two containers
`frontend` and `backend` to this network using `alpine` images. Ensure that
`frontend` can communicate with `backend` using the container name.
6. **Container Updates**:
- Update the `app-container` container running the `myapp:v1` image to
`myapp:v2` while ensuring zero downtime. Describe the steps needed to achieve this.
7. **Environment Variables**:
- Create a container `webapp` using the `httpd` image. Pass the environment
variables `APP_ENV=production` and `DB_HOST=database.local` during container
creation.
8. **Resource Limiting**:
- Create a container named `resource-limited` using the `alpine` image. Limit
the container to use a maximum of `512MB` of memory and `1` CPU core.
9. **Data Backup**:
- Create a container `backup-container` using the `busybox` image. Mount the
`/var/lib/mysql` directory from the host to `/backup/mysql` inside the container
and run a daily backup script to compress the data.
10. **Volume Management**:
- Create a volume named `appdata` and use it to create a `myapp` container with
the `myapp_image`. Ensure that the volume is mounted to `/app/data` inside the
container.
Here are 10 more practice questions related to container management to help you
deepen your understanding:
### Additional Practice Questions:
1. **Network Configuration**:
- Create a `redis` container named `redis-cache` using the `redis` image.
Connect it to a user-defined network `cache-network` and verify that it is
reachable by another container named `app-server` using `alpine`.
2. **Container Lifecycle Management**:
- Create a `webapp` container using the `httpd` image. Start, stop, restart, and
delete the container. Verify each state change using the appropriate `podman` or
`docker` commands.
3. **Custom Image Building**:
- Write a `Containerfile` to create an image named `my-python-app` that runs a
simple Python script. The script should print "Hello from the container". Build the
image and run a container from it.
4. **Environment Configuration**:
- Create a container named `db-container` using the `postgres` image. Pass the
environment variables `POSTGRES_USER=admin` and `POSTGRES_PASSWORD=secret` during
container creation.
5. **Volume Management**:
- Create a volume named `data-vol` and use it to create a `mysql` container that
stores its database in this volume. Verify that data persists even after the
container is removed and recreated.
6. **Container Logs**:
- Run a `nginx` container named `webserver` and access its logs using `podman
logs` or `docker logs`. Redirect the logs to a file named `webserver-logs.txt` in
the host's `/home/user/logs` directory.
7. **Container Resource Limits**:
- Create a `busybox` container named `limited-container` and limit its CPU usage
to `0.5` CPU cores and `256MB` of memory. Run a command inside the container that
continuously uses CPU (e.g., `yes`).
8. **Bind Mounts**:
- Create a `nodejs` container named `node-app` using a `node` image and bind
mount the host directory `/home/user/node-app` to `/app` inside the container.
Ensure that changes in the host directory are reflected inside the container.
9. **Container Networking**:
- Create a bridge network named `custom-net` and run two containers, `nginx-
proxy` and `app-server`, connected to `custom-net`. Make sure `nginx-proxy` can
forward traffic to `app-server` using its container name.
10. **Automatic Restart Policies**:
- Create a `webapp` container using `myapp_image` and configure it to always
restart if it stops or crashes. Verify that the container restarts automatically
using `podman` or `docker`.