Installing the required software with Docker
Docker is the most widely used framework for implementing operating system-level virtualization. This technology allows you to have an independent container: a layer that is lighter than a virtual machine but still allows you to compartmentalize software. This mostly isolates all processes, making it feel like each container is a virtual machine. Containers will be discussed in more detail in Chapter 14, Cloud Basics.
Docker works quite well at both extremes of the development spectrum: it’s an expedient way to set up the content of this book for learning purposes and could become your platform of choice for deploying your applications in complex environments.
Conda and Docker are key tools to help maintain software compatibility and reproducibility across different systems and libraries. We’ll discuss reproducibility more in Chapter 15, Workflow Systems.
Note
This recipe is an alternative to the previous recipe. Normally, if you have a Mac and are using it for your Jupyter notebooks, you will not need the Docker container. If you have a Windows machine or cannot get certain code to work in your environment, the Docker container can be useful to provide you with an environment that is set up properly already for you.
Getting ready
The first thing you have to do is install Docker. Go to https://www.docker.com/. Install Docker Desktop for your appropriate operating system (remember to check the Apple versus Intel silicon discussion in the Technical requirements section if you are using macOS). You’ll also need to sign up for a Docker account and record your username and password.
How to do it...
Docker Desktop must be running and you need to be signed in before downloading the Docker file. To get started, follow these steps:
- Use the following command from your Terminal:
docker build -t bio https://github.com/PacktPublishing/Bioinformatics-with-Python-Cookbook-Fourth-Edition.git#main:docker/main
Tip
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository. Doing so will help you avoid any potential errors related to the copying and pasting of code.
You can find the commands for this section in the chapter’s README.md file.
- Now you are ready to run the container, as follows:
docker run -ti -p 9875:9875 -v YOUR_DIRECTORY:/data bio
- Replace
YOUR_DIRECTORYwith a directory on your operating system. This will be shared between your host operating system and the Docker container.YOUR_DIRECTORYwill be seen in the container in/dataand vice versa.In this case,
-p 9875:9875will expose the container’s TCP port9875on the host computer port,9875.Especially on Windows (and maybe on macOS), make sure that your directory is actually visible inside the Docker shell environment. If not, check the official Docker documentation on how to expose directories. To access the Docker image while it’s running, hover over the Docker Desktop icon. All the files available in the book’s GitHub repository will be mirrored in the Docker image.
- Now you are ready to use the system. Point your browser to
http://localhost:9875and you should get the Jupyter environment.
If this does not work on Windows, check the official Docker documentation (https://docs.docker.com/manuals/) on how to expose ports.
See also
- Docker is the most widely used containerization software and has seen enormous growth in usage in recent times. You can read more about it at https://www.docker.com/.
- A security-minded alternative to Docker is Red Hat Openshift, which can be found at https://www.redhat.com/en/technologies/cloud-computing/openshift.
- If you are not able to use Docker, for example, if you do not have the necessary permissions, as will be the case for most compute clusters, then take a look at Singularity at https://www.sylabs.io/singularity/.
- For a good course on Docker, see: https://www.udemy.com/course/docker-and-kubernetes-the-complete-guide/.