<h2>What is a docker?</h2><blockquote><p>Package Software into Standardized Units for Development, Shipment and Deployment:<br>A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.<br>Container images become containers at runtime and in the case of Docker containers - images become containers when they run on Docker Engine. Available for both Linux and Windows-based application, containerized software will always run the same, regardless of the infrastructure. Containers isolate software from its environment and ensure that it works uniformly despite differences for instance between development and staging.</p></blockquote><p>Source : <a href="https://www.docker.com/resources/what-container" target="_blank">What is a Container</a></p><h2><br></h2><h2>Differences against Virtual Machines?</h2><blockquote><p>Containers and virtual machines have similar resource isolation and allocation benefits, but function differently because containers virtualize the operating system instead of hardware. Containers are more portable and efficient.</p></blockquote><p><img src="/media/django-summernote/2021-06-03/0bf1f817-c068-49e9-af74-12fa36892d4d.png" style="width: 100%;"><br></p><p>Source : <a href="https://www.docker.com/resources/what-container" target="_blank" style="background-color: rgb(255, 255, 255);">What is a Container</a><br></p><h2><br></h2><h2>Why docker?</h2><p>Followings are advantages</p><ul><li>With the consolidate with CICD pipeline (link), consistent CICD automation made for any language. For my case, I can use same CICD script for react, Rshiny, dash, and streamlit app.</li><li>It is a container, and it is portable does not matter unique environment at local OS or cloud differences. As long as you could run container app at your local, it could be run anywhere.</li><li>It could enable some language based app to deploy to cloud. For example, most of cloud like AWS, GCP, Digital Ocean, Cloud foundry etc. do not have Rshiny build pack so we need to prepare Rshiny server on our own. We could prepare only using docker container</li><li>Consistent environment can be made by Dockerfile, so it would not cause dependency issues.</li></ul><h2><br></h2><h2>Basic Commands</h2><h4>Basic Operations</h4><p>Build a docker</p><pre># shell script docker build .</pre><p>Build a docker and assign specific name</p><pre># shell script docker build -f <docker repo name>/<container name> .</pre><p>Run docker</p><pre style="line-height: 1.42857;"># shell script docker run <image ID or specific image name></pre><p>Run docker with mapping route</p><pre style="line-height: 1.42857;"># shell script docker run -p <localhost port>:<port inside the container> <image ID or image name></pre><p style="line-height: 1.42857;">Run docker with volume mount</p><pre style="line-height: 1.42857;"># shell script docker run -v <outside docker directory>:<inside docker directory> <image ID or image name></pre><p>Run docker with detached mode (run container at background)<br></p><pre style="line-height: 1.42857;"># shell script docker run -d <image ID or image name></pre><p>Run docker with container name assigned</p><pre style="line-height: 1.42857;"># shell script docker run --name <container name> <image ID or image name></pre><p>Stop docker</p><pre># shell script docker stop <container ID or container name></pre><p><br></p><h4>Other Operations</h4><p>Start docker</p><pre># shell script docker start <container ID or container name></pre><p>Kill docker</p><pre># shell script docker kill <container ID or container name></pre><p>Go inside docker (typically for a issue verification)</p><pre style="line-height: 1.42857;"># shell script docker exec -it <container ID or container name> bash(or sh)</pre><p>Push to docker hub</p><pre style="line-height: 1.42857;"># shell script docker push <docker repo name>/<container name></pre><p style="line-height: 1.42857;"><br></p><h4>Maintenance</h4><p>Show running container list</p><pre style="line-height: 1.42857;"># shell script docker ps</pre><p>Show all container list</p><pre style="line-height: 1.42857;"># shell script docker ps -a(or --all)</pre><p>Show image list</p><pre style="line-height: 1.42857;"># shell script docker images</pre><p>Delete container</p><pre># shell script docker rm <container id or container name></pre><p>Delete image</p><pre># shell script docker rmi <image name or image id></pre><p>Remove all stopped containers, networks not used by al least one container, dangling images, and build cache</p><pre># shell script docker system prune</pre><p>See history</p><pre style="line-height: 1.42857;"># shell script docker log <container ID or container name></pre><p><br></p><h2>Single container vs Multi containers</h2><p>Single container has a limitation. We only have one app and it won't work in case we would like to have multiple container running at the same time such as following case;</p><ol><li>Create DB container as well as web container</li><li>Create front end container(e.g. React) and back end/worker container(e.g. Python)</li><li>Create nginx container to manage port/load balance separating out from web container</li></ol><p>This requires `Docker-Compose` and will be documented separately</p>
<< Back to Blog Posts
Back to Home