{"id":1854,"date":"2024-01-17T09:37:13","date_gmt":"2024-01-17T03:37:13","guid":{"rendered":"http:\/\/techsatwork.com\/?p=1854"},"modified":"2024-01-17T09:56:11","modified_gmt":"2024-01-17T03:56:11","slug":"creating-docker-image-for-jupyter-notebook","status":"publish","type":"post","link":"https:\/\/techsatwork.com\/?p=1854","title":{"rendered":"Creating Docker Image for Jupyter Notebook"},"content":{"rendered":"\n\n\n<p>Below are the steps for creating docker image for running a Jupyter Notebook with the latest python module . \u00a0You can run this for any operating systems that supports docker. If you haven&#8217;t downloaded the docker desktop. Please do so from <a href=\"https:\/\/www.docker.com\/products\/docker-desktop\">here<\/a><\/p>\n<p>Creating a Docker image with Jupyter Notebook and Python involves several steps, including setting up a Dockerfile, building the image, and running a container. Here&#8217;s a basic guide on how to do it:<\/p>\n<p>1. Install Docker: If you haven&#8217;t already, install Docker on your machine. You can download it from the official Docker website.<br \/><br \/>2. Create a Dockerfile: A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Here&#8217;s a simple example of a Dockerfile that sets up a Jupyter Notebook with Python:<\/p>\n<p><span style=\"color: #ff6600;\"># Use the latest official Python image as the base image<\/span><br \/><span style=\"color: #ff6600;\">FROM python:latest<\/span><\/p>\n<p><span style=\"color: #ff6600;\"># Set the working directory in the container<\/span><br \/><span style=\"color: #ff6600;\">WORKDIR \/usr\/src\/app<\/span><\/p>\n<p><span style=\"color: #ff6600;\"># Create a non-root user and switch to it<\/span><br \/><span style=\"color: #ff6600;\">RUN useradd -m myuser<\/span><br \/><span style=\"color: #ff6600;\">ENV PATH=&#8221;\/home\/myuser\/.local\/bin:${PATH}&#8221;<\/span><br \/><span style=\"color: #ff6600;\">USER myuser<\/span><\/p>\n<p><span style=\"color: #ff6600;\"># Copy files from the host to the container<\/span><br \/><span style=\"color: #ff6600;\">COPY &#8211;chown=myuser:myuser path_to_your_files\/ \/usr\/src\/app\/<\/span><\/p>\n<p><span style=\"color: #ff6600;\"># Install Jupyter Notebook as the non-root user<\/span><br \/><span style=\"color: #ff6600;\">RUN pip install &#8211;user notebook<\/span><\/p>\n<p><span style=\"color: #ff6600;\"># Make port 8888 available to the world outside this container<\/span><br \/><span style=\"color: #ff6600;\">EXPOSE 8888<\/span><\/p>\n<p><span style=\"color: #ff6600;\"># Run Jupyter Notebook as a non-root user<\/span><br \/><span style=\"color: #ff6600;\">CMD [&#8220;jupyter&#8221;, &#8220;notebook&#8221;, &#8220;&#8211;ip=0.0.0.0&#8221;, &#8220;&#8211;port=8888&#8221;, &#8220;&#8211;no-browser&#8221;, &#8220;&#8211;NotebookApp.token=&#8221;&#8221;]<br \/><br \/><\/span>3. Build the Docker Image Again: Save the modified Dockerfile and then build your Docker image again. Use the docker build command in the directory where your Dockerfile is located:<br \/><br \/><span style=\"color: #ff6600;\">docker build -t jupyter-notebook .<br \/><br \/><\/span>4. This command builds a new Docker image using the updated Dockerfile. Replace jupyter-notebook with your preferred image name.<br \/>Run the Docker Container: After successfully building the image, run the container:<br \/><br \/><span style=\"color: #ff6600;\">docker run -p 8888:8888 jupyter-notebook<\/span><\/p>\n<p>5. You should see a URL on the log . Cut and paste this on a browser to get to the webUI for Jupyter Notebook<\/p>\n<p>\u00a0<\/p>\n<p><code><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below are the steps for creating docker image for running a Jupyter Notebook with the latest python module . \u00a0You can run this for any operating systems that supports docker. If you haven&#8217;t downloaded the docker desktop. Please do so from here Creating a Docker image with Jupyter Notebook and Python involves several steps, including [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","site-transparent-header":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[1053,142,1052],"tags":[1054,1055,1049],"class_list":["post-1854","post","type-post","status-publish","format-standard","hentry","category-docker","category-linux","category-python","tag-docker","tag-jupyter-notebook","tag-python"],"_links":{"self":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/1854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1854"}],"version-history":[{"count":3,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/1854\/revisions"}],"predecessor-version":[{"id":1862,"href":"https:\/\/techsatwork.com\/index.php?rest_route=\/wp\/v2\/posts\/1854\/revisions\/1862"}],"wp:attachment":[{"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techsatwork.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}