Ever wanted to run a small experiment but were afraid to run it on your machine lest it would change important configurations you wouldn't know how to reverse?
Maybe you're still not super comfortable with Linux and fear running it on your server could interfere with your current projects hosted there... what are you to do?
You could SSH into a Raspberry Pi if you have one and try it out there, but their memory and processing power are very limited.
What if I just want to play around with some scripts I found in GitHub without any worry of messing anything up?
To get started, head over to Docker Desktop and download the product.
Upon installation, a user friendly guide will quickly explain the basics of Docker, which I recommend doing. Once you've done this, let's play to make our very own first container:
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings. (Source)
From your CLI run the following command:
docker pull ubuntu
This will download the latest official Ubuntu image available.
Next, we will create a Docker container running this Ubuntu image by entering this command:
docker run -i -t ubuntu /bin/bash
The command will start the container, and you will then be redirected to the bash shell of your newly created Ubuntu container. If you notice, the “root@[random_numbers]:/#” prompt is actually the bash shell prompt within the Ubuntu container that we have just created. Type
ls to list the root directory.
From here, you can play and install any dependencies you might want to explore and set-up any scripts you might want to test.
Now that you've seen the power and potential of having an isolated container to experiment, you might want to exit the container or destroy it.
To exit the container simply type
exit from within the shell prompt in Ubuntu. This will return you to your system's shell. Your container is now offline.
You may have noticed a two-word
container_name appeared on your Docker console when you created the Ubuntu container. As you might have learned on the initial Getting Started presentation, this is a random name generated for each container. Mouse over it and you'll see a trashcan icon 🗑 which at pressing it will destroy this container so you can try again.
Using the same two-word
container_name on your Docker console to reference your container, run the following command:
docker start -i container_name
Learning to create an isolated testing environment might just give you the courage and peace of mind to try new things and learn faster. I hope this very short and brief guide helps introduce a new tool to your stack.