Create Selenoid Image With DockerFile

226 views Asked by At

I need to publish a Dockerfile that contains https://aerokube.com/selenoid.

This has to be a Dockerfile so I can publish it to our container registry which will be used as a service container as part of the pipeline/text execution https://learn.microsoft.com/en-us/azure/devops/pipelines/process/service-containers?view=azure-devops&tabs=yaml

Here is my dockerfile

FROM alpine:3.14

# Update Package
RUN apk update

# Install Selenoid Configuration Manager
RUN wget -O /usr/bin/cm https://github.com/aerokube/cm/releases/download/1.8.5/cm_linux_amd64 \
    && chmod +x /usr/bin/cm

# create dir
RUN mkdir -p /etc/selenoid

# Copy browsers.json
COPY  browsers.json /etc/selenoid/browsers.json

EXPOSE 4444

CMD["/usr/bin/cm", "-conf", "/etc/selenoid/browsers.json"]

My browsers.json file is located in the same directory as the Dockerfile.

In my local testing I get the following error when trying to run the container

Error: unknown command "/etc/selenoid/browsers.json" for "cm"
Run 'cm --help' for usage.

I have also tried updating the command to be

CMD ["/usr/bin/cm", "selenoid","start", "-conf", "/etc/selenoid/browsers.json"]

But the error is even more insane

Failed to initialize: [can not access Docker: make sure you have Docker installed and current user has access permissions]

Changing CMD to ENTRYPOINT is the same result

3

There are 3 answers

1
VapeBoro On

Not sure if it's a typo but in your question you have a space missing in the original Dockerfile.

CMD["/usr/bin/cm", "-conf", "/etc/selenoid/browsers.json"]

Should be:

CMD ["/usr/bin/cm", "-conf", "/etc/selenoid/browsers.json"]
0
VonC On

The error unknown command "/etc/selenoid/browsers.json" for "cm" suggests there is an issue with the command syntax in the Dockerfile. The command parameters are not being recognized correctly.
Make sure the CMD instruction is properly formatted as a JSON array.

CMD ["/usr/bin/cm", "selenoid", "start", "-conf", "/etc/selenoid/browsers.json"]

And the error message can not access Docker: make sure you have Docker installed and current user has access permissions indicates that the Selenoid service is unable to access Docker.
Try and mount the Docker socket inside your container. That can be done by adding a volume mount when running the Docker container.

docker run -v /var/run/docker.sock:/var/run/docker.sock your-image-name

Finally, using ENTRYPOINT instead of CMD is advisable when you want your container to run as an executable.

Your revised Dockerfile would be:

FROM alpine:3.14

RUN apk update && \
    wget -O /usr/bin/cm https://github.com/aerokube/cm/releases/download/1.8.5/cm_linux_amd64 && \
    chmod +x /usr/bin/cm && \
    mkdir -p /etc/selenoid

COPY browsers.json /etc/selenoid/browsers.json

EXPOSE 4444

ENTRYPOINT ["/usr/bin/cm"]
CMD ["selenoid", "start", "-conf", "/etc/selenoid/browsers.json"]
1
vania-pooh On

You are doing weird things. CM tool was never expected to be published in a container. This is just like a setup.exe for quick Selenoid installation. How to build a Docker images is described in this documentation section: https://aerokube.com/selenoid/latest/#_contributing_development Simply copy browsers.json as /etc/selenoid/browsers.json after doing steps from the docs and provide this path to /usr/bin/selenoid command using -conf flag. Original Dockerfile is published here: https://github.com/aerokube/selenoid/blob/master/Dockerfile