What is Docker?
Imagine that Docker is like a big ship carrying containers. Well, inside the containers will contain the merchandise. Hypothesize that the merchandise are "Docker images", so structure of docker similar :
1. What is the container?
What is the containers?
Container is like virtual environment in python. It's contain several Docker image, Docker image is instance or object of container.
- Container is a way to package applications with all the necessary dependencies and configuration.
- Easily shared and moved around between a development team or deployment and operations team
- Makes development and deployment more efficient
2. Different before container & after container
- Installation process different on each OS environment
- Many steps where something could go wrong
- own isolated environment
- package with all needed configuration
- one command to install the app
- run same app with 2 different versions
Docker compare to Virtual Machine
Docker virtualize is the application layer. So, when you dowload a docker image, it actually contains the applications layer of the operating system and some other applications installed on top of it. And it use the kernel of the host because it doesn't have its own kernel.
Virtual Machine (VM) has the applications layer and its own kernel, so virtualize is the complete operating system, which means that when you download a virtual machine image on your host, it doesn't use your kernel. It puts up its own.
So what is this difference between Docker and Virtual Machine actually mean ? So first of all, the size of Docker images are much smaller because they just have to implement one layer. A second one is the speed so you can run and start docker container much faster than VM. The third difference is compatibility.
Docker can install on the multiple flatforms, such as : Mac, Linux, Window. Link tutorial Iam working with deep learning then by default you use ubuntu. Detail description install : link
- Set up the responsitory
$ sudo apt-get update $ sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg $ echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Install Docker Engine
$ sudo apt-get update $ sudo apt-get install docker-ce docker-ce-cli containerd.io
- Inspect install
$ sudo docker run hello-world
If result is " Hello from docker ", the installation was successful.
Base commands in docker
- docker ps : list running containers
- docker ps -a : lists running and stopped container
- docker images: list images
- docker rmi: remove image
docker rmi <image_id>
- docker build: building image
docker build -t <image_name> .
- docker run: start new container with a command
docker run -it --rm -d -p <port_host>:<container_host> --name <name> <image_name>
- docker pull: pull docker image from docker hub
- docker push: push image to docker hub
docker tag <container_name> <user_name>/<responsitory>:<tag>
docker push <user_name>/<responsitory>:<tag>
- docker stop: stop the container
docker stop <container_name>
- docker start: start stopped container
- docker logs: debug containers
docker logs <containers_id>
- docker exec -it: use review or debug containers
docker exec -it <container_id> /bin/bash
You can refer to PhamDinhKhanh's article very good.
1. Build Dockerfile
Dockerfile is used to create an image for our application. This image will run on any host or environment with Docker installed.
Let's have an overview of whats in our Dockerfile:
- FROM: A Dockerfile must start with a From instruction with an argument that has anather image.
- RUN: Will execute terminal commands during build image.
RUN pip install -r requirements.txt <br> RUN pip install tensorflow
- WORKDIR: It is similar to the cd command.
- LABEL: Provide metadata information for images such as: email, company,author,...
- EXPOSE: Port
- COPY: This command copies files from the local system onto the Docker image.
- ADD: similar COPY
- CMD: This command specifies the program or file that will be excecuted when the container initializes.
Syntax: CMD ["executable", "param1","param2"]
- ENV: parameters environment
- ARG: similar argument parser in python
File requirements.txt help pack libraries to run
next time or refer to :https://phamdinhkhanh.github.io/2020/11/17/DockerDL.html#11-khái-niệm
Install docker: https://docs.docker.com/engine/install/ubuntu/
Build Dockerfile anaconda3: https://github.com/okwrtdsh/anaconda3
Build Dockerfile pytorch: https://github.com/anibali/docker-pytorch/tree/master/dockerfiles
Video tutorial : https://www.youtube.com/watch?v=3c-iBn73dDE
All Rights Reserved