Today I started working with Docker. So please bear with me. I'm not even sure if the title makes sense. I just installed Tensorflow using Docker and wanted to run a script. However, I got the following error saying that Matplotlib is not installed.
Traceback (most recent call last):
File "tf_mlp_v3.py", line 3, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
I used the following command to install Tensorflow
docker pull tensorflow/tensorflow:latest-gpu-jupyter
How can I now add other python libraries such as Matplotlib to that image?
To install any packages, you first need to update the OS. Step 3: After you have updated the Docker Container, you can now install the Firefox and Vim packages inside it. You can now easily use these packages through the bash itself.
A Docker image contains application code, libraries, tools, dependencies and other files needed to make an application run.
Dockerfile contains instructions to prepare Docker image with our Python Application. Following is the content of Dockerfile. FROM python COPY . /src CMD ["python", "/src/PythonExample.py"] 4. Build Docker Image Run the following command in Terminal, from python-application directory, to create Docker Image with Python Application.
If you need to add extra libraries, and if you want to include the install of these libraries in a build process, you probably need a Dockerfile . For instance, if you want to install requests, a minimalist Dockerfile could be as follows: Create such a file in myproject/, then cd in myproject/ and simply run docker build .
After installing the python you can create a python script and run easily. But one thing you should note that any editor is not available in docker ubuntu container thus you have to first install it using the apt-get install command. After install lets create a run.py file and then write the line print (“Hello Data Science Learner”) and run it.
This comes very handy when you are using a python app such as django or flask and you want to maintain your docker container using the same python script that you use for the application. To use the python library API for docker, you need to install a package called docker−py. You can do so using the following pip command.
To customize an image you generally want to create a new one using the existing image as a base. In Docker it is extremely common to create custom images when existing ones don't quite do what you want. By basing your images off public ones you can add your own customizations without having to repeat (or even know) what the base image does.
Add the necessary steps to a new Dockerfile.
FROM tensorflow/tensorflow:latest-gpu-jupyter
RUN <extra install steps>
COPY <extra files>
RUN
and COPY
are examples of instructions you might use. RUN
will run a command of your choosing such as RUN pip install matplotlib
. COPY
is used to add new files from your machine to the image, such as a configuration file.
Build and tag the new image. Give it a new name of your choosing. I'll call it my-customized-tensorflow
, but you can name it anything you like.
Assuming the Dockerfile
is in the current directory, run docker build
:
$ docker build -t my-customized-tensorflow .
Now you can use my-customized-tensorflow
as you would any other image.
$ docker run my-customized-tensorflow
Add this to your Dockerfile after pulling the image:
RUN python -m pip install matplotlib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With