Run an OMERO client in Docker
Overview
Teaching: 10 min
Exercises: 25 minQuestions
How do I create a Docker image for a complex application?
Objectives
Create a Dockerfile for a complex application
This builds on the previous lesson to create a fully working Docker image for the OMERO python client.
Installing OMERO.py’s dependencies
We install OMERO.py in a virtual environment.
To install OMERO.py we need additional dependencies, most notably the Ice Python bindings.
We install a pre-compiled version matching our Docker image i.e. rockylinux
and the Python version installed i.e. 3.9
.
FROM rockylinux:9
LABEL maintainer="OME"
RUN dnf install -y epel-release
RUN dnf install -y python-pip
RUN dnf install -y python3
RUN python3 -mvenv /opt/omero/web/venv3
# But this is a shortcut that installs a precompiled version to install Ice Python
RUN /opt/omero/web/venv3/bin/pip install https://github.com/glencoesoftware/zeroc-ice-py-rhel9-x86_64/releases/download/20230830/zeroc_ice-3.6.5-cp39-cp39-linux_x86_64.whl
RUN /opt/omero/web/venv3/bin/pip install omero-py
RUN useradd omero
WORKDIR /home/omero
USER omero
docker build -t my-omeropy-image .
docker run -it my-omeropy-image
/opt/omero/web/venv3/bin/omero version
OMERO.py version:
5.20.0
Connect to workshop.openmicroscopy.org
usingCLI commands, e.g.:
/opt/omero/web/venv3/bin/omero login -s workshop.openmicroscopy.org
Default commands
When you run my-omeropy-dockerfile
the bash
shell is automatically started. This is the default in the parent rockylinux:9
image.
Change the default command by adding CMD
to the end of your Dockerfile:
CMD ["/opt/omero/web/venv3/bin/omero"]
Re-build, and run:
docker build -t my-omeropy-image .
docker run -it my-omeropy-image
OMERO Python Shell. Version 5.20
Type "help" for more information, "quit" or Ctrl-D to exit
omero>
This time you enter the OMERO shell directly.
Can you pass command-line arguments?
docker run -it my-omeropy-image version
docker: Error response from daemon: oci runtime error: container_linux.go:265: starting container process caused "exec: \"version\": executable file not found in $PATH".
If you pass a command line to docker run
it overwrites the default, so you need to pass the whole command line including omero
:
docker run -it my-omeropy-image /opt/omero/web/venv3/bin/omero version
OMERO.py version:
5.20.0
ENTRYPOINT vs CMD
You can make the Docker image behave as the
omero
command using anENTRYPOINT
, see the Docker documentation for details.
Best practice for writing Dockerfiles
Writing a Dockerfile is easy, but there are several guidelines you should follow when developing a Docker image for production. See this article in the Docker documentation for more details.
Key Points