Install In Docker - mdPlusPlus/motioneye GitHub Wiki
There are three options to run motionEye in Docker.
Method 1 (easiest) is to use the automatically built and published Docker images from ghcr.io. Unfortunately the automatic image creation is not yet available for stable releases of motionEye, but it will be available with the next release. The currently existing images are built from the actual development in the dev
branch. Images for x86 and Raspberry Pi architectures are available.
Method 2 is a bit more complex creating the image on your own.
Method 3 is just a bit more complex than method 2, but gives you a container with Debian 10, motion 4.3.2-1, and the latest development build of motionEye (0.42.1 with the Privacy Mask enhancement, and others. Currently Method 3 is only working for amd64, but hopefully will be available for Debian 11, and armhf soon.
The Dockerfile
for the automatically built image and a sample docker-compose.yml
are both in the /docker
directory of the project (https://github.com/motioneye-project/motioneye/tree/dev/docker) stored.
If you like to contribute or testing motioneye
project, you can use the docker container.
Image from GitHub Container Registry
The automatically built images are available on GHCR. Tags for stable releases of motionEye currently do not exist.
Download the image with the following command. The image is built for x86 architecture using the current development branch of motionEye.
docker pull ghcr.io/motioneye-project/motioneye:edge
Use the following command to start motionEye inside a Docker container. You don't need to download the images first. If you just fire the run command, the images are downloaded automatically, if they do not exist locally.
docker run --name="motioneye" \
-p 8765:8765 \
--hostname="motioneye" \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/motioneye:/etc/motioneye \
-v /var/lib/motioneye:/var/lib/motioneye \
--restart="always" \
--detach=true \
ghcr.io/motioneye-project/motioneye:edge
Add additional port mappings with the -p
parameter if you want to use the streaming feature of motion: -p 8765:8765 -p 8081:8081
; for cameras added, numbering of ports used for streaming starts from 8081 (second camera will use port 8082, etc). Ports used for streaming can be later changed in motionEye (Video Streaming -> Streaming Port) but should always match the ones that are being exposed from Docker.
If using additional services that make use of ports in the 808x range, then default mapping can be edited to avoid conflicting by mapping higher range port numbers that are not in use by other services (i.e., -p 8765:8765 -p 58081:8081 -p 58082:8082
)
Change the two bind paths /etc/motioneye
and /var/lib/motioneye
according to your needs. The first contains the configuration files for motionEye and the second will be used as file storage for still images and movies. The bound file /etc/localtime
is necessary for a proper timezone configuration inside the container using the timezone of the host.
To forward a video device of your host use an additional parameter like the following
--device=/dev/video0
Build instructions
Second and third options to get the motionEye Docker image start here to build it on your own. The actually good maintained version of Docker images currently only exist for the dev
branch.
-
Clone your fork or official
motioneye
projectgit clone -b dev https://github.com/motioneye-project/motioneye.git
-
Build your motionEye Docker image from the
Dockerfile
. enter project folder:cd motioneye
If you want to build the method 3 container, you need to replace the docker/Dockerfile with the contents at the end of this page. You would then continue with the instructions here.
If you would like to build the docker image from the official project:
docker build --build-arg VCS_REF=$(git rev-parse HEAD) \
--build-arg BUILD_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") \
-t your_tag -f docker/Dockerfile .
Note: If /etc/motioneye/motioneye.conf does not exist, it is copied from /usr/share/motioneye/extra/motioneye.conf.sample (Not overwrite the volume)
-
Have a cup of coffee while the image builds :)
-
Either start a container using
docker run
or use the provided sampledocker-compose.yml
together withdocker-compose
.
Using the docker run
command is described under the first chapter describing how to run the ready to use images.
With docker-compose.yml:
Edit docker-compose.yml
and modify the timezone to your own (A list is available at http://php.net/manual/en/timezones.php).
Also edit the two mount points to a directory in your system. Save the file, and then run:
docker-compose -f docker-compose.yml -p motioneye up -d
Test your development:
If you would contribute or test your development, update the code, and rebuild the docker container, see the step 2.
Replacement extra/Dockerfiles
New contents for the extra/Dockerfile for amd64:
FROM debian:buster-slim
LABEL maintainer="Marcus Klein <[email protected]>"
ARG BUILD_DATE
ARG VCS_REF
LABEL org.label-schema.build-date=$BUILD_DATE \\
org.label-schema.docker.dockerfile="extra/Dockerfile" \\
org.label-schema.license="GPLv3" \\
org.label-schema.name="motioneye" \\
org.label-schema.url="https://github.com/motioneye-project/motioneye/wiki" \\
org.label-schema.vcs-ref=$VCS_REF \\
org.label-schema.vcs-type="Git" \\
org.label-schema.vcs-url="https://github.com/motioneye-project/motioneye.git"
# By default, run as root.
ARG RUN_UID=0
ARG RUN_GID=0
COPY . /tmp/motioneye
ADD https://github.com/Motion-Project/motion/releases/download/release-4.3.2/buster_motion_4.3.2-1_amd64.deb ./motion.deb
RUN echo "deb http://snapshot.debian.org/archive/debian/$(date +%Y%m%d) buster contrib non-free" >>/etc/apt/sources.list && \\
apt-get update && \\
DEBIAN_FRONTEND="noninteractive" apt-get -t buster --yes --option Dpkg::Options::="--force-confnew" --no-install-recommends install \\
curl \\
ffmpeg \\
libmicrohttpd12 \\
libpq5 \\
lsb-release \\
mosquitto-clients \\
python-jinja2 \\
python-pil \\
python-pip \\
python-pip-whl \\
python-pycurl \\
python-setuptools \\
python-tornado \\
python-tz \\
python-wheel \\
v4l-utils \\
./motion.deb \\
default-libmysqlclient-dev && \\
# Change uid/gid of user/group motion to match our desired IDs. This will
# make it easier to use execute motion as our desired user later.
sed -i -e "s/^\\(motion:[^:]*\\):[0-9]*:[0-9]*:\\(.*\\)/\\1:${RUN_UID}:${RUN_GID}:\\2/" /etc/passwd && \\
sed -i -e "s/^\\(motion:[^:]*\\):[0-9]*:\\(.*\\)/\\1:${RUN_GID}:\\2/" /etc/group && \\
pip install /tmp/motioneye && \\
# Cleanup
rm -rf /tmp/motioneye && \\
apt-get purge --yes python-setuptools python-wheel && \\
apt-get autoremove --yes && \\
apt-get --yes clean && rm -rf /var/lib/apt/lists/* && rm -f /var/cache/apt/*.bin
ADD extra/motioneye.conf.sample /usr/share/motioneye/extra/
# R/W needed for motioneye to update configurations
VOLUME /etc/motioneye
# Video & images
VOLUME /var/lib/motioneye
CMD test -e /etc/motioneye/motioneye.conf || \\
cp /usr/share/motioneye/extra/motioneye.conf.sample /etc/motioneye/motioneye.conf ; \\
# We need to chown at startup time since volumes are mounted as root. This is fugly.
chown motion:motion /var/run /var/log /etc/motioneye /var/lib/motioneye /usr/share/motioneye/extra ; \\
su -g motion motion -s /bin/bash -c "/usr/local/bin/meyectl startserver -c /etc/motioneye/motioneye.conf"
EXPOSE 8765