self-taught
I bet in your programming life, you might once said: "It works on my computer!".
The reason for that problem would be varied. It would either be one or more files are missing, or a software version mismatch, or different environment, …
Well, Docker was born, trying to solve that problem.
In short, Docker is used to pack your software to run it on any hardware. By this, your app can be built, run and shipped consistently.
It is recommended to use Docker desktop because it gives you the vision of what container is running and their log, in case you want to debug.
https://www.docker.com/products/docker-desktop/
*You should also add Docker extension to your IDEA
Before we start dockerizing an app, there are 3 things you must know:
To dockerize an app:
1. add a Dockerfile to your app
It's a plain text file that has instruction to package the app into an IMAGE.
2. with Dockerfile we can build the docker image
When the build process was done, you can you docker push
command to push this Image to dockerhub or any cloud service so others can use it too.
To run the container use docker run -p 9000:8080 imageID
(9000 is the local port and 8080 is docker port, it means to expose the container to your local machine).
3. add volume
When we stop the container, all state and data will be lost, but in many situations, we'd want to keep the data and share it to other containers as well.
In that case, we can create Volume. Volumes are dedicated folder in host machine, use this to share data between container.
To create a volume, use docker volume create volumeName
.
Then, when we run a docker, we can mount it to this shared volume using the –mount flag:
https://docs.docker.com/engine/reference/commandline/run/#add-bind-mounts-or-volumes-using-the–-mount-flag
4. Run multiple containers
Each container should run only 1 process, for example, beside the app running process, we also want to access mysql data base and run cache with redis.
To be able to do that, we can use docker-compose.yml
.
Finally, run docker-compose up
to run all containers, instead of running one by one.
==> That's a wrap everyone. This is just an overview of Docker, you should take a look in theri documents for more complex cases.
https://docs.docker.com