Difference between revisions of "Docker"
(Updated to reflect 9.0 Changes) |
|||
Line 14: | Line 14: | ||
--publish 1984:1984 \ | --publish 1984:1984 \ | ||
--publish 8984:8984 \ | --publish 8984:8984 \ | ||
− | --volume | + | --volume "$(pwd)/basex/data":/srv/basex/data \ |
basex/basexhttp:latest</pre> | basex/basexhttp:latest</pre> | ||
Line 53: | Line 53: | ||
=Running your own Application= | =Running your own Application= | ||
− | If you want to add your own application in a Docker image, create an image {{Code|FROM basex/basexhttp:[tag]}} with {{Code|[tag]}} being the BaseX version you’re developing against. | + | If you want to add your own application in a Docker image, create an image {{Code|FROM basex/basexhttp:[tag]}} with {{Code|[tag]}} being the BaseX version you’re developing against. |
+ | Unless configured otherwise, you will add your application code to {{Code|/srv/basex/webapp}} and modules to {{Code|/srv/basex/repo}}. | ||
+ | |||
==Example: DBA== | ==Example: DBA== | ||
Line 62: | Line 64: | ||
FROM basex/basexhttp:latest | FROM basex/basexhttp:latest | ||
MAINTAINER BaseX Team <basex-talk@mailman.uni-konstanz.de> | MAINTAINER BaseX Team <basex-talk@mailman.uni-konstanz.de> | ||
− | COPY . /srv/webapp | + | COPY . /srv/basex/webapp |
</pre> | </pre> | ||
Line 74: | Line 76: | ||
<pre> | <pre> | ||
− | COPY .basex /srv | + | COPY .basex /srv/basex |
</pre> | </pre> | ||
Line 93: | Line 95: | ||
===Installing Debian Packages=== | ===Installing Debian Packages=== | ||
− | The {{Code|basex/basexhttp}} Docker image is build own the official Maven Docker image, which | + | The {{Code|basex/basexhttp}} Docker image is build own the official Maven Docker image {{Code|maven:3-jdk-8-alpine}}, which in turn derives from alpine. |
+ | You can add arbitrary packages via APK. Make sure to switch to the {{Code|root}} user context before installing packages and back to the {{Code|basex}} user afterwards. As common in the Docker environment, you need to fetch the package catalog using {{Code|apt-get update}} before installing packages and should clean up afterwards to keep the image small. This example installs some libraries required for image manipulation and adds them to the {{Code|$CLASSPATH}}: | ||
<pre> | <pre> | ||
USER root | USER root | ||
− | RUN | + | RUN apk update && apk add --no-cache git |
− | + | ||
− | |||
USER basex | USER basex | ||
− | |||
− | |||
</pre> | </pre> |
Revision as of 17:27, 23 March 2018
This page is part of the Developer Section.
The BaseX server is available as automated build basex/basexhttp
on the Docker Hub, providing both release and nightly builds. All images are automatically rebuilt if Docker provides updated base images.
Contents
Running a BaseX Container
Updated with Version 9.0: New default Home Directory.
To start a BaseX container based on the latest development release publishing the BaseX server and HTTP ports 1984 and 8984 and bind-mounting your user’s data
directory, run
docker run -ti \ --name basexhttp \ --publish 1984:1984 \ --publish 8984:8984 \ --volume "$(pwd)/basex/data":/srv/basex/data \ basex/basexhttp:latest
By passing any other BaseX executable, you can also for example run a BaseX client connecting to the linked BaseX server for management operations on the BaseX command line:
docker run -ti \ --link basexhttp:basexhttp \ basex/basexhttp:latest basexclient -nbasexhttp
BaseX is run under the basex
user with fixed user ID 1984. The user’s home directory is /srv
. Several ports are exposed:
Port | Description |
1984 | Server port |
8984 | HTTP port |
8985 | HTTP stop port |
Leaving BaseX defaults but --publish
ing them under another external port is recommended if you want to change the ports.
Security Considerations
The Docker image ships the unchanged default credentials. Especially if you publish the server port 1984 or link a public DBA instance against the container, make sure to change the default credentials. When publishing ports, consider which interfaces to bind to, paying special attention to the server port.
A common use case will be linking a well-researched and mature reverse proxy link nginx against the application container. Goals are to reduce exposure of BaseX and Jetty, adding TLS-encryption, serve static resources like images and perform URL rewrites as needed. If you need to access the command line, you can always docker exec
into the container and run basexclient
.
Running your own Application
If you want to add your own application in a Docker image, create an image FROM basex/basexhttp:[tag]
with [tag]
being the BaseX version you’re developing against.
Unless configured otherwise, you will add your application code to /srv/basex/webapp
and modules to /srv/basex/repo
.
Example: DBA
An example for creating your own Docker image based on basex/basexhttp
is the DBA application. A Dockerfile
was added to the source code’s root directory. The very simple file contains only few statements:
FROM basex/basexhttp:latest MAINTAINER BaseX Team <basex-talk@mailman.uni-konstanz.de> COPY . /srv/basex/webapp
For general production usage, you should choose a fixed version instead of the development branch behind latest
, so your application does not suddenly break because of unnoticed API changes. The most relevant part happens in the COPY
statement, which adds the file contents to the webapp
directory. That’s already it -- you’re ready to run.
Advanced Usage
BaseX Configuration
If you need to adjust the BaseX configuration to tune the default options, add a .basex
file to /srv
:
COPY .basex /srv/basex
Options not defined in the .basex
file with be automatically set to the default values. Users and passwords can be defined by adding a users.xml
file, which is described on the User Management page.
Jetty Configuration
If you need to change the embedded web server configuration, you can always COPY
a WEB-INF
folder containing the required files and overwrite the predefined configuration.
Java Runtime Parameters
Larger applications and databases might require adjusted JRE parameters like increasing the memory limit. You can change those by setting the BASEX_JVM
environment variable:
ENV BASEX_JVM="-Xmx2048m"
Installing Debian Packages
The basex/basexhttp
Docker image is build own the official Maven Docker image maven:3-jdk-8-alpine
, which in turn derives from alpine.
You can add arbitrary packages via APK. Make sure to switch to the root
user context before installing packages and back to the basex
user afterwards. As common in the Docker environment, you need to fetch the package catalog using apt-get update
before installing packages and should clean up afterwards to keep the image small. This example installs some libraries required for image manipulation and adds them to the $CLASSPATH
:
USER root RUN apk update && apk add --no-cache git USER basex