This article was written to help you with basic knowledge of Docker and as an individual review assignment of PPL CSUI 2021
When developing software with your team, your software application resources will grow until it very hard to maintain. There will be dependencies issues where some of the system dependency has different versions installed in each machine whether on the developer machine, even in production. To help solve problems like there, Docker is here to help.
The idea of docker is to isolate your code with their dependencies into ‘containers’. It means your software will be packaged with all the dependencies installed and enables it to runs quickly and reliably from one environment to another.
You can see the concept of containers as the same as virtual machines. But there are some differences:
- Docker containers share the same system resources but able to behave like independent machines.
- Multiple workloads on the same operating system are allowed.
- It is cheap. Imagine a machine that able to run 2 VM, you can run ten containers in the same machine with each container has the same workload as the VM without any problem. This means fewer resources = less cost and maintenance.
Docker has two concepts: image and containers. Docker image is the definition of what will going to be executed, and a container is an instance where the given image runs.
Working with docker
- Define the docker image: Dockerfile
Docker image defined in a special text file, Dockerfile. In this file, you need to define all the steps to be run. Here a docker implementation in my project using react. If you want to know more about Dockerfile, hit here!
2. Build the DockerFile
Now we can compile our Dockerfile into a docker image. Use this command in your terminal in the Dockerfile directory to compile it into a docker image
$ docker build .
Or if you want to use tag your images,
$ docker build -t [image-name]
After compiling the Dockerfile, check your docker image created by using
$ docker images
3. Run the docker images
You can run the docker image using this command!
$ docker run -name [CONTAINER_IMAGE_NAME]
Docker with Gitlab
If you want your machine to automatically in your production stage, here an example of implement docker in the production stage using Gitlab.
Thank you for your enthusiasm to learn Docker. I hope this article can help you with your project and assignment.
See you next time!