如何使用webdevops/*系列Docker容器?新手求使用指引
Hey there! Glad you're diving into the webdevops/* Docker images—they’re a fantastic collection for streamlining web development, server management, and DevOps workflows. Since you already have a handle on docker run --rm, let’s build on that to put these images to work effectively.
Basic Usage (Leveraging docker run --rm)
The --rm flag is perfect for temporary test runs or one-off tasks because it automatically cleans up the container once it stops. Here’s a simple example to kick things off with an Apache web server:
docker run --rm -p 8080:80 webdevops/apache:latest
-p 8080:80maps your host’s port 8080 to the container’s port 80, so you can access the server athttp://localhost:8080.- The
webdevops/apache:latestimage pulls the most recent official Apache build from the repository.
Common Use Cases with Popular webdevops Images
Let’s walk through practical examples for some of the most useful images in the repo:
PHP + Apache Development Environment
If you’re working on a PHP project, this image lets you run your code instantly without setting up a local PHP stack:
docker run --rm -p 8080:80 -v $(pwd)/src:/app webdevops/php-apache:latest
-v $(pwd)/src:/appmounts your localsrcdirectory (where your PHP files live) into the container’s/appdirectory. Any changes you make locally will reflect immediately in the container.
Custom Nginx Reverse Proxy
Use this to spin up a configurable Nginx instance quickly:
docker run --rm -p 80:80 -v $(pwd)/nginx.conf:/opt/docker/etc/nginx/nginx.conf webdevops/nginx:latest
-v $(pwd)/nginx.conf:/opt/docker/etc/nginx/nginx.confreplaces the container’s default Nginx config with your custom file. This is great for setting up reverse proxy rules, SSL termination, or custom routing.
pgAdmin for PostgreSQL Management
Manage PostgreSQL databases via a web UI with minimal setup:
docker run --rm -p 5050:80 -e PGADMIN_DEFAULT_EMAIL=admin@example.com -e PGADMIN_DEFAULT_PASSWORD=secret webdevops/pgadmin:latest
-esets environment variables to configure the initial admin account. Access pgAdmin athttp://localhost:5050using the credentials you provided.
Customizing Containers
Most webdevops images are highly configurable via environment variables and mounted files:
- Environment Variables: Adjust service settings on the fly. For example, increase PHP’s memory limit:
docker run --rm -p 8080:80 -e PHP_MEMORY_LIMIT=256M -v $(pwd)/src:/app webdevops/php-apache:latest - Mount Configuration Files: Most images store configs in
/opt/docker/etc/. For Apache, you can override the default virtual host config by mounting your own file to/opt/docker/etc/apache2/vhost.conf.
Persisting Data (When --rm Isn’t Right)
While --rm is great for temporary tasks, you’ll want to persist data for services like databases. For example, with the webdevops/mysql image:
docker run -d -p 3306:3306 -v mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mysecret webdevops/mysql:latest
-druns the container in the background.-v mysql-data:/var/lib/mysqluses a named Docker volume to persist MySQL data—even if you delete the container, your data stays intact.
To learn more about a specific webdevops image, run docker run --rm webdevops/<image-name>:latest help to view built-in documentation, or use docker inspect webdevops/<image-name>:latest to check exposed ports, default environment variables, and entrypoint details.
内容的提问来源于stack exchange,提问作者e-israel

