Skip to content
Advertisement

Docker run with arguments from a configuration file

I’ve built a docker image in order to publish a jupyter notebook to my team.

The jupyter notebook runs inside a docker container by running a docker run command containing numerous arguments (such as mounts and environment variables for AWS credentials).

The current instructions I published for running the docker require you to copy and paste the entire docker run command and execute it in a terminal window.

The script works fine, but I wonder if there is a way to specify the source from a file and run the docker run command with that file as the run configuration (including the run arguments).

The idea is to do something similar to what applies when building an image with a Dockerfile. Basically, you execute docker build -f ./Dockerfile to build the image.

Is it possible to do something like this with docker run?

I want to include my docker_run_configuration file (yml, json, etc.) at the project location and instruct the team to simply docker run -f ./docker_run_configuration.yml.

Advertisement

Answer

The solution to your problem is docker compose.

Here are the official samples and guide.

Advanced TIP

You can pass external variables to YAML like in the following example:

version: 3

services:
  main_service:
    image: service-image
  environment:
    - SERVICE_OPTION: ${EXTERNAL_SERVICE_OPTION}
EXTERNAL_SERVICE_OPTION="A service option..." docker-compose up
Advertisement