Creating Docker Images¶
Available since version 0.10.0
dockerize command to create a Docker image from
the project. Images created from Anaconda Projects are
configured to execute a single defined command
anaconda-project.yml file chosen at build time.
Images built with
dockerize will have a fully prepared
env_spec for the desired
command and expose port 8086 if the command listens for HTTP requests.
In order to utilize the
dockerize command you will need to
have Docker and source-to-image (s2i) installed.
You can install s2i using Conda
conda install -c ctools source-to-image
Build a docker image to run a supplied command
anaconda-project dockerize --command <command-name> -t <image name>
Run the Docker image and publish port 8086
docker run -p 8086:8086 <image name>
It is necessary to add
-p 8086:8086 in order to publish port 8086 from the anaconda-project container
out to the host. The second entry in the
-p flag must be
8086 while the first entry
can be any valid unused port on the host. See the Docker container networking docs for more details.
Build Docker images¶
By default running the
dockerize command will create a
Docker image to execute the default command.
The default command is determined in the following order
- The command named
- The first command listed in the project file if no command is named
s2i-anaconda-project builder images have Miniconda and
anaconda-project installed. When the
command is run the following steps are performed.
- The project is archived to a temporary directory to ensure that files listed in your
.projectignore(including the local
envsdirectory) are not copied into the Docker image.
s2i buildcommand is run from the temporary directory to construct a new Docker image from the builder image.
The steps in the
s2i build process are
- The temporary project directory is added to the image.
- The s2i assemble script is run to prepare the
env_specfor the desired command.
- Conda clean is run to reduce the size of the output Docker image.
dockerize command accepts several optional arguments
- The named command to execute in the
RUNlayer of the Docker image. Default:
defaultSee the HTTP commands section below.
- The name of the output Docker image in the format
name:tag. By default Default: “<project-name>:latest”, where <project-name> is taken from the name tag in the anaconda-project.yml file.
- The s2i builder image name to use.
conda/s2i-anaconda-project-ubi8By default this is image is pulled from DockerHub when
dockerizeis run. See the Custom Builder Image section below to construct your own builder images.
- s2i build arguments
- Any further arguments or those supplied after
--will be given to the
s2i buildcommand. See the s2i build documentation for available build flags.
The default builder image for
anaconda-project dockerize is
conda/s2i-anaconda-project-ubi8. To see
other available builder images on DockerHub click here.
When the docker image is run the s2i run script is executed with the supplied command. The full run command is
anaconda-project run $CMD --anaconda-project-port 8086 --anaconda-project-address 0.0.0.0 --anaconda-project-no-browser --anaconda-project-use-xheaders
This ensures that the command communicates over port 8086 if it supports the HTTP Commands.
If your desired command is not an HTTP command or you wish not to use the Jinja2 template features you must add
supports_http_options: false to the command specification in the
anaconda-project.yml file. When
supports_http_options is set to
false the HTTP arguments are completely ignored when the command is executed.
In addition to the channel configuration available in the
file you may need to supply custom Conda configuration parameters
in order to build the Docker image.
To provide a custom Conda configuration, place a
.condarc file at the top-level
of your project directory.