My First Experience with Docker

· 3 min read

Docker has been a hot topic in recent years, and many companies have already widely adopted this technology. If you don’t know about it, it might seem a bit behind the times, so it’s worth spending some time to understand it.

Introduction to Docker

Docker is an open-source software project that automates the deployment of applications in software containers. It provides an additional software abstraction layer on Linux operating systems and an automated management mechanism for operating system-level virtualization [1]. Docker uses resource isolation mechanisms in the Linux kernel, such as cgroups, and Linux kernel namespaces, to create independent software containers. These can operate under a single Linux entity, avoiding the additional overhead of starting a virtual machine [2]. The Linux kernel’s support for namespaces completely isolates the application’s view of the working environment, including process trees, networks, user IDs, and mounted file systems, while the kernel’s cgroups provide resource isolation, including CPU, memory, block I/O, and network. Starting from version 0.9, Docker began including the libcontainer library as its own way to directly use the virtualization facilities provided by the Linux kernel, building upon the abstraction provided by libvirt’s LXC and systemd-nspawn interfaces. According to industry analysis firm “451 Research”: “Docker is a tool that can package applications and their dependencies into virtual containers that can run on any Linux server. This helps achieve flexibility and portability, allowing applications to run anywhere, whether in public cloud, private cloud, standalone machines, etc.”

Excerpt from Wikipedia, View original

Docker’s Capabilities

Docker provides a “one-stop” container solution for application development and deployment. It helps developers efficiently and quickly build applications, achieving “Build, Ship and Run Any App, Anywhere,” thus reaching the goal of “build once, run anywhere.” Using Docker, we can:

  • Faster delivery and deployment of application environments
  • More efficient resource utilization
  • More convenient migration and scalability
  • Easier application update management

Getting Started - Creating a MySQL Container

I discovered that Docker can solve environment problems. Thinking about the various development environment configuration and version issues I’ve encountered in the past, I realized that using Docker could make things much better. For example, in my development work, I need to use MySQL, but different projects may require different versions. I can’t install multiple versions on my computer, and if I install it system-wide, running it as a service for long periods also consumes system resources. This is indeed a problem.

Using Docker seems to be a quick solution. So I downloaded and installed it, and got started.

Downloading Docker

I decisively downloaded it from the official website for safety and convenience. For Mac, it’s a DMG file that you download, then click to run and install.

Starting Docker

Click to run and start Docker, execute docker images, and see that there are no images yet. Pull from the hub:

docker pull mysql:5
docker pull mysql

As shown above, I pulled the latest version (8) and 5.x of MySQL, Redis, and some other commonly used database images Execute $ docker run -p 3306:3306 --name mysql5 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5
CLI usage instructions can be found here (Official Documentation)

After successful startup, I tried connecting to MySQL with Navicat - no problem. With just one line of code, MySQL was successfully installed.

  • If I want to uninstall this, I just need to stop it, then remove it
  • If MySQL 8 is released and I want to try it immediately, no problem - just run a container with the MySQL 8 image Environment installation is that simple.

Final Thoughts

This is just a preliminary attempt, but it has already solved some of my development environment problems. More usage and exploration will continue.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover