如何在Aerokube Selenoid Docker镜像上启动文件服务器?
Hey there! Great to hear you've successfully spun up Selenoid via Docker and got it connected. Let's get that file server up and running in no time—here's how:
1. Prepare a Local Directory for Files
First, create a directory on your host machine to store files that'll be accessible via the Selenoid file server. This directory will be mounted into the Docker container, so make sure it has proper permissions for read/write access:
mkdir -p ~/selenoid-files chmod 777 ~/selenoid-files # Quick setup for testing; use more restrictive permissions in production environments
2. Update Your Selenoid Docker Run Command
Selenoid has a built-in file server that just needs a startup flag to activate. Modify your existing Docker run command to include three key changes:
- Mount your local directory to
/opt/selenoid/filesinside the container - Add the
-enable-file-serverflag to turn on the file server - Map port 8080 (the default file server port) from the container to your host
Here's an example adjusted command (tweak paths/ports to match your existing setup):
docker run -d --name selenoid \ -p 4444:4444 \ -p 8080:8080 \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /etc/selenoid:/etc/selenoid \ -v ~/selenoid-files:/opt/selenoid/files \ aerokube/selenoid:latest \ -enable-file-server
3. Verify the File Server is Working
Once the container restarts, check if the file server is live by visiting http://localhost:8080 in your browser. You'll see a simple interface where you can upload files, browse existing ones, or download content from the directory.
Optional: Customize File Server Settings
If you need to adjust the default port or file directory, use these additional flags in your Docker command:
-file-server-port <port>: Set a custom port (e.g.,-file-server-port 9090to use port 9090 instead of 8080)-file-server-dir <path>: Specify a different internal container path (just make sure to mount your local directory to this new path)
Alternatively, define these settings in a dedicated Selenoid config file (e.g., selenoid.conf):
{ "enableFileServer": true, "fileServerDirectory": "/opt/selenoid/files", "fileServerPort": 8080 }
Then start Selenoid with this config:
docker run -d --name selenoid \ -p 4444:4444 \ -p 8080:8080 \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /etc/selenoid:/etc/selenoid \ -v ~/selenoid-files:/opt/selenoid/files \ -v ~/selenoid.conf:/etc/selenoid/selenoid.conf \ aerokube/selenoid:latest \ -conf /etc/selenoid/selenoid.conf
Using the File Server in Tests
Once set up, you can reference files in your Selenium tests using the URL pattern: http://<selenoid-host>:<file-server-port>/files/<your-file-name>. For example, if you uploaded test-data.csv, you'd access it at http://localhost:8080/files/test-data.csv.
内容的提问来源于stack exchange,提问作者Ajay EP

