L&D series: Embark on a Docker voyage with Whiny the whale
Learning and Development chapter 9.
“Focus on what you can control” — somebody said this to me. So, let me take a vacation to explore something with a fictional character named Whiny in the midst of this uncontrolled pandemic (this is one wish that I want to fulfill).
A long long long time ago, I tried an interview in one of the big company. One of the requirements of the position is Docker. What is Docker? And why it is so damn popular? In fact, many companies have included Docker on their list of job requirements (things that I only found out at a later date).
Docker
I would say that Docker is a open source tool that simplifies our workflow from building applications to deploying them in any environment. Docker provided a container to allow us to create an application (with the libraries and dependencies) as one package. For example, I’m using MacBook (with masOS Catalina) but my team provided Linux as a server, this difference will be resolved using docker.
So, how do you build Docker? (sorry but I don’t get the author’s explanation etc. Just get to the practice!). And who is this Whiny? (he’s cute actually)
Okay got it, Captain (roger with thanks on behalf of Whiny). For information, since I’m using macOS, I will only explain for macOS needs only. Let’s have a sail !!!
Installation
- Download from https://www.docker.com/products/docker-desktop or https://hub.docker.com/editions/community/docker-ce-desktop-mac/. Then install as usual.
- Verify the installation with
sudo docker run hello-world
.
Create Project
Just create any simple project to start. I have main.go file. What would I do with this file? Keep that mind to create the content of our Dockerfile.
Create Image
What is image?
A Docker image is a read-only template that contains a set of instructions for creating a container that can run on the Docker platform. It provides a convenient way to package up applications and preconfigured server environments, which you can use for your own private use or share publicly with other Docker users.
Docker images are also the starting point for anyone using Docker for the first time. — https://jfrog.com/knowledge-base/a-beginners-guide-to-understanding-and-building-docker-images/
Let’s build our first image.
$ docker build -t docker-go-test .
Explanation :
--tag , -t
Name and optionally a tag in the ‘name:tag’ format — https://docs.docker.com/engine/reference/commandline/build/
Give any name you want for your first c̵̵̵h̵̵̵i̵̵̵l̵̵̵d̵ image.
Run Image
$ docker run docker-go-test
You will see Whiny say a greetings inside a container.
So, Whiny is the courier in charge of delivering what we’ve created to any environment. He is the whale who will cry if he can’t convey his mandate. So, as a proof that he has carried out his mandate, he conveys greetings after run the mandate successfully. Good job, Whiny ! (Don’t cry anymore :D)
Tips and trick
- List all images
$ docker image ls
- List all containers
$ docker ps-a
- Start a container
$ docker start [CONTAINER ID]
- Stop a container
$ docker stop [CONTAINER ID]
- Delete all containers
$ docker rm -vf $(docker ps -a -q)
- Delete all images
$ docker rmi -f $(docker images -a -q)
- See container’s logs
$ docker logs [CONTAINER ID]
- Docker run
https://docs.docker.com/engine/reference/commandline/run/
- Cheat sheet
https://kapeli.com/cheat_sheets/Dockerfile.docset/Contents/Resources/Documents/index
Don’t say any excuse like that anymore, okay?! Because Whiny will help us. — MperMperPisang
References :
- https://opensource.com/resources/what-docker
- https://medium.com/better-programming/php-how-to-run-your-entire-development-environment-in-docker-containers-on-macos-787784e94f9a
- https://medium.com/free-code-camp/a-beginners-guide-to-docker-how-to-create-your-first-docker-application-cc03de9b639f
- https://jfrog.com/knowledge-base/a-beginners-guide-to-understanding-and-building-docker-images/
- https://docs.docker.com/engine/reference/commandline/build/
- https://kapeli.com/cheat_sheets/Dockerfile.docset/Contents/Resources/Documents/index
- https://docs.docker.com/engine/reference/commandline/run/