How to Add Custom Requirements to an Existing Docker Image?

0
0
Asked By CuriousCoder42 On

I'm running a Jupyter server using the `quay.io/jupyter/scipy-notebook` image in a container. The reason for this setup is that I need a Python library that won't run on Windows, so I execute the Jupyter kernel in Docker and connect to it from VS Code on Windows. While the scipy-notebook image comes loaded with useful libraries, I need a few additional ones for my project. Right now, I set up the container by running `docker run`, attaching a shell, and executing `apt-get install` and `pip install` commands manually. I want to know if there's a way to streamline this with a single command to set up the scipy-notebook container and install the necessary packages automatically. Is there a way to incorporate this into the `docker run` command, or should I create a Dockerfile that uses the scipy-notebook image as a base? What's the best approach?

2 Answers

Answered By DockerDude99 On

It’s best to create your own image! Use the existing scipy-notebook image as a base, then simply add the packages you need with `RUN` commands in your Dockerfile. After building that new image, you can use it going forward without the need for manual installs.

Alternatively, you might want to run a container from the existing image, make your changes while exec’d into it, and then commit those changes as a new image using `docker commit`. But the Dockerfile route is definitely cleaner for ongoing projects!

PackageSeeker88 -

I see that. I’m just unsure about how to handle the options I set in the `docker run` command like -p, --user, -e, etc. Could those be included too?

Answered By StackOverflowSavant On

Creating a Dockerfile is definitely the way to go. You can start with `FROM quay.io/jupyter/scipy-notebook` and then use `RUN` to install the additional libraries you need (just make sure they’re available as Ubuntu packages). If you have any custom scripts or binaries, you can use `COPY` to add them to your container. Also, consider writing a docker-compose file that sets your service up with the build option pointing at your new Dockerfile to keep everything organized!

CuriousCoder42 -

Thanks! I'll go ahead and start setting that up.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.