Docker is a system for creating and running OS-level virtualization also known as "containerization". Docker runs software packages known as containers which are isolated from each other and can run different operating systems and software. These containers allow for different projects to run on the same machine regardless of tech stack or dependencies installed on that machine. Containers are configured by images which specify the OS and build steps, which allows for the same exact container to be built over and over again.
- MacOS (Although Docker will run on Linux and Windows as well this article is specific to MacOS)
- Homebrew (The missing package manager for MacOS)
- Docker Hub Account
Install Docker Engine
To start with we need to install the Docker Engine. This is the software which builds and runs Docker containers.
Run the following Brew command to install Docker
brew install docker
And it is as simple as that (thanks to Homebrew)
Next login to the Docker Hub so that you can download images for various operating systems
And log in with your Docker Hub credentials (if you do not have any you can create a free account here)
To start with we need to download the Alpine Linux image. Alpine is made especially for Docker containers and is very small and lightweight.
docker pull alpine
And now for the Dockerfile to specify how to build and what to run in a container. Create a new file named Dockerfile in an empty directory. Enter the following couple of lines into this new file. You can ignore everything after the '#' as those are just comments.
FROM alpine:3.7 # This specifies which OS to use RUN apk add --no-cache mysql-client # This will install MySQL server ENTRYPOINT ["mysql"] # On container start run 'mysql'
Now its time to deploy our Docker container. The following command downloads the needed image and creates the container named simple_mysql from the Dockerfile in the current directory
docker build -t simple_mysql .
And now we can run the Docker container and have a working MySQL database running on Alpine Linux
docker run simple_mysql:latest
In this brief introduction to Docker containers we saw how to:
- Install the Docker Engine on MacOS
- Login to the Docker Hub
- Create a basic Dockerfile
- Build and Deploy a container running MySQL
While this just barely scratches the surface as to what Docker can do I hope that it has helped get you started.