What is Docker?
Docker is a container platform basically, but we should also explain “What is container?” then. A container is a standardized unit of software, and you can imagine it as a fishbowl with fishes and all the accessories which you wanted inside. It’s the best environment for that fish and it can live freely inside that bowl. Imagine that you can specify the water temperature, amount of water, bowl size, fish count, fish breed, accessories and so on, and when you specify these settings once. You can order the same environment countlessly and you and rest assured that your fish will behave the same in all the fishbowls.
The easiest way to go is Docker for Mac or Docker for Windows depending on your OS. This will install the necessary utilities for your computer, but if you want some GUI for your containers and images there is a tool called Kitematic. Kitematic is also tool made by Docker and it is good for first-timers to see the running containers and their states in GUI.
You can download Kitematic from here.
First things first, make sure your Docker is up and running. You can check the installation from the command line.
The mission was trying to run a Redis server on a Docker container, so this “Usage” part is explained by Redis. For running a Redis instance in Docker, we need Redis image to run a container with. So, let’s run this container then!
If your terminal log also looks like this, everything should be working fine, but first, let’s explain the command which we wrote.
-d stands for detached, so our server can run in the background, otherwise, it’ll occupy our command line.
-p stands for the port. Never forget, these containers are virtual machines. You are not running them locally, so you need to expose the container’s port and attach to your computer’s port. By the way, 6379 is default port for Redis.
–name stands for name obviously. It’s a good idea that you provide a name for your container, otherwise Docker will generate a random name like “cactus_lover”. For management purposes, provide a name for your container.
redis is our image name and if you don’t specify a version or tag, it will pull the latest version of that image. You can specify the tag with a colon. (Ex: redis:latest)
Testing the container
If everything is perfect, we can test our server is it running or not. Remember that, we run the server in detached mode. For testing or using the CLI, we need shell access.
If you see this on your CLI, congratulations! You are running your Redis server in Docker, but before that let’s explain the command.
-it stands for -i and -t. Let’s explain separately.
-i stands for interactive. It allows us to send inputs to the container.
-t stands for “Allocate a pseudo-TTY”, which allocates a terminal for us to control our container.
my-redis-instance is our container name. See, it’s much better readable and understandable than “cactus_lover”.
ping is a command for checking the server whether it is running or down.
Also for stopping a container, simply just run:
Docker is an endless ocean. You can dive deep and try different images and different configurations. This is the most basic usage of Docker. There are more technologies like “Docker Swarm”, “Docker Compose” and “Kubernetes”. Maybe I will cover them also here, some time soon!
I hope you liked what you read and I am really looking forward to seeing you in the next one! If you don’t want to miss any content, you can subscribe to the website and I will let you know whenever something new going on here!
Also you can reach out to me from the “Contact” section. Feel free to share your thoughs or suggest any ideas. I am reading all the messages and I will reply yours as soon as possible!
As you might know me, I like coffee and high-quality content. If you want to support me and my effort, why not a little caffeine boost ha? 😎
Until next one,