This Dockerfile uses the selenium standalone chrome debug image as its base, exposes ports 4200, 4444, and 3000, and sets up directories and environment variables for a Chrome browser testing environment. It also modifies the entry_point.sh script to modify Chrome preferences and change the exit behavior to report a cleaner shutdown.
npm run import -- "Run selenium inside of docker"
FROM selenium/standalone-chrome-debug
EXPOSE 4200
EXPOSE 4444
EXPOSE 3000
ENV DBUS_SESSION_BUS_ADDRESS /dev/null
ENV CHROME_USER_DATA_DIR /usr/profile
WORKDIR /home/seluser
# I added this part?
USER root
RUN mkdir /usr/profile
RUN mkdir /usr/downloads
RUN chown seluser:seluser -R /usr/profile
RUN chown seluser:seluser -R /usr/downloads
RUN chmod 777 -R /usr/profile
RUN chmod 777 -R /usr/downloads
#VOLUME /usr/profile
#VOLUME /data/downloads
RUN sed -i '/wait \$NODE_PID/ised -i -e s/exit_type":"Crashed/exit_type":"None/g /usr/profile/Default/Preferences &' /opt/bin/entry_point.sh
RUN sed -i '/wait \$NODE_PID/ised -i -e s/exited_cleanly":false/exited_cleanly":true/g /usr/profile/Default/Preferences &' /opt/bin/entry_point.sh
# Use official selenium image
FROM selenium/standalone-chrome-debug as base
# Expose required ports
EXPOSE 4200
EXPOSE 4444
EXPOSE 3000
# Set environment variables
ENV DBUS_SESSION_BUS_ADDRESS /dev/null
ENV CHROME_USER_DATA_DIR /usr/profile
# Set working directory
WORKDIR /home/seluser
# Copy permissions and ownership
COPY permissions.sh /permissions.sh
RUN sh /permissions.sh
# Configure Chrome User Data
RUN sed -i '/wait \$NODE_PID/ised -i -e s/exit_type":"Crashed/exit_type":"None/g /usr/profile/Default/Preferences' /opt/bin/entry_point.sh
RUN sed -i '/wait \$NODE_PID/ised -i -e s/exited_cleanly":false/exited_cleanly":true/g /usr/profile/Default/Preferences' /opt/bin/entry_point.sh
# Create directories
RUN mkdir /usr/profile
RUN mkdir /usr/downloads
# Configure permissions
COPY permissions.sh /permissions.sh
RUN sh /permissions.sh
# Use a new user and root as builder
USER seluser
RUN chown seluser:seluser -R /usr/profile
RUN chown seluser:seluser -R /usr/downloads
RUN chmod 777 -R /usr/profile
RUN chmod 777 -R /usr/downloads
# Use Alpine for size reduction
FROM alpine:latest
# Copy necessary directories
COPY --from=0 /usr/profile /usr/profile
COPY --from=0 /usr/downloads /usr/downloads
# Set default command
CMD ["tail", "-f", "/dev/null"]
Dockerfile Breakdown
FROM selenium/standalone-chrome-debug
: Uses the selenium standalone chrome debug image as the base.EXPOSE 4200
, EXPOSE 4444
, EXPOSE 3000
: Exposes the ports 4200, 4444, and 3000 from the container to the host.ENV DBUS_SESSION_BUS_ADDRESS /dev/null
: Sets the DBUS_SESSION_BUS_ADDRESS environment variable to /dev/null
.ENV CHROME_USER_DATA_DIR /usr/profile
: Sets the CHROME_USER_DATA_DIR environment variable to /usr/profile
.WORKDIR /home/seluser
: Sets the working directory to /home/seluser
.USER root
: Sets the user to root
(not in the original Dockerfile, added later).RUN mkdir /usr/profile
and RUN mkdir /usr/downloads
: Creates the directories /usr/profile
and /usr/downloads
.RUN chown seluser:seluser -R /usr/profile
and RUN chown seluser:seluser -R /usr/downloads
: Changes the ownership of the directories to seluser:seluser
.RUN chmod 777 -R /usr/profile
and RUN chmod 777 -R /usr/downloads
: Sets the permissions of the directories to 777 (not recommended in production).RUN sed -i '/wait \$NODE_PID/ised -i -e s/exit_type":"Crashed/exit_type":"None/g /usr/profile/Default/Preferences &' /opt/bin/entry_point.sh
: Modifies the entry_point.sh
script to replace exit_type":"Crashed
with exit_type":"None
in the /usr/profile/Default/Preferences
file.RUN sed -i '/wait \$NODE_PID/ised -i -e s/exited_cleanly":false/exited_cleanly":true/g /usr/profile/Default/Preferences &' /opt/bin/entry_point.sh
: Modifies the entry_point.sh
script to replace exited_cleanly":false
with exited_cleanly":true
in the /usr/profile/Default/Preferences
file.