In production the profiler server runs in a docker container. In this document we'll describe some of the basic commands around creating and handling this docker container.
The Dockerfile describes the image. It could be run directly using the command:
yarn docker:build
The image generated from this command has a tag from the name and the version in
package.json, currently profiler-server:dev
.
Using yarn docker:build --pull
will update the base image, it's useful to do
it from time to time.
We can run the last built image in a new container with the command:
yarn docker:run
This makes use of the local file .env to provide environment variables.
Especially the environment variable JWT_SECRET
needs to be set.
Be careful that the .env
file doesn't use quotes or superfluous space characters.
If the variable GCS_AUTHENTICATION_PATH
is set the pointed file will be
mounted to the docker instance as well, so that Google Storage authentication
works. Make sure to change its group to "10001" so that the docker image can
access it.
The app should listen on port 8000. The container is named profiler-server
.
Pressing Ctrl-C will gracefully close the app and the container, then delete the container.
Pressing Ctrl-P CTRL-Q will put the container in background. You can use yarn docker:stop
to stop it then.
This can easily be done with the command:
yarn docker:run:detached
Then the container can be stopped with:
yarn docker:stop
yarn docker:run
runs the script bin/docker-run.js, which is basically a shortcut for:
docker run \
-t -i \
-p 8000:8000 \
--rm \
--name profiler-server \
--env-file .env \
--mount type=bind,source=<path-to-GCS-config>,target=<path-to-GCS-config>,readonly \
profiler-server:dev
Here is a quick explanation of the command line parameters:
-t
allocates a pseudo-tty, while-i
makes the container interactive. These two parameters makes it possible to interact with the container. Especially Ctrl-C can gracefully stop the container.-p 8000:8000
makes the container listen on port 8000, and binds it to the inner port 8000 which is the default port configured while building the container. (Please see below to change this port.)--rm
removes the container when it stops.--name
name this container so that it's easier to reference in commands.--env-file .env
imports environment variable to the newly created instance.--mount type=bind,source=XXX,target=XXX,readonly
: this makes it possible to authenticate to Google Cloud Storage by sharing the authentication file.
The script can take some parameters. See below and run yarn docker:run --help
to find out more.
It's easy to run a bash shell as the running user:
yarn docker:run bash
It's also possible to run a shell as root:
yarn docker:run --user root bash
Similarly this is how we can change the listening port:
yarn docker:run -p <local port>
He images we use for production are public, you can pull latest versions with:
- for master:
docker pull mozilla/profiler-server:master-latest
- for production:
docker pull mozilla/profiler-server:production-latest
Then run them with the command node bin/docker-run <name of the image>
.
With the command docker ps
you can find out which containers are currently
running, as well as their names. Then docker stop <container name>
will stop
it properly.
When using the default commands yarn docker:run
or yarn docker:run:detached
,
the container is called profiler-server
and is stopped using yarn docker:stop
.
docker ps
shows the running containersdocker image ls
ordocker images
shows the images on your systemdocker image rm <image...>
deletes imagesdocker container ls --all
ordocker ps --all
shows all the containers on your systemdocker container stop <container...>
stops the container. It will be deleted automatically only if--rm
was used when starting it.docker container rm <container...>
deletes containers