Objective of this paper
Introduce the basic knowledge of docker Learn to package a custom docker and let others use it successfully
reference material
- Introduction to Docker - ruanyifeng's Weblog (ruanyifeng.com)
- How to build mmdetection environment in docker and encapsulate it into image_ Kongyan 66 blog - CSDN blog
- Docker -- from introduction to practice
- docker_practice/SUMMARY.md at master ยท yeasy/docker_practice (github.com)
- How to play docker? This wave of docker actual combat summary (very comprehensive) finally caught up- Zhihu (zhihu.com)
- Docker image container basic operation - common commands - iDEAAM - blog Garden (cnblogs.com)
- How to play docker? This wave of docker actual combat summary (very comprehensive) finally caught up- Zhihu (zhihu.com) -Orientation and setup | Docker Documentation
- Check the running container in linux and talk about the common commands of Docker container_ weixin_39568597 blog - CSDN blog
- Build a docker you want - Zhihu (zhihu.com)
- What is Docker? It's enough to read this dry article- Zhihu (zhihu.com) (Getting Started Guide)
- Docker tutorial - MOOC (imooc.com)
- [introduction to docker] 10 minutes to quickly learn docker - Zhihu (zhihu.com) (introductory Practice Guide)
- Docker actual combat summary (very comprehensive) - Zhihu (zhihu.com)
- Check the running container in linux and talk about the common command Weixin of Docker container_ 39568597 blog - CSDN blog
Basic concepts of docker
The birth background of docker
docker was born to solve the problem of inconsistency between development environment and multiple software versions.

docker is not a virtual machine
docker installation
sudo wget -qO- https://get.docker.com | sh sudo usermod -aG docker usernamexxx
Basic concepts of docker
Overall architecture of docker: Note that docker daemon is responsible for controlling command execution

image.png
There are several concepts in docker:
- dockerfile:
- image:
- container:
In fact, you can simply understand image as an executable program, and container is a running process.
If you need source code to write a program, you need dockerfile to "write" an image. Dockerfile is the source code of the image and docker is the "compiler".
Therefore, we only need to specify what programs are required and what configurations depend on in the dockerfile, and then hand over the dockerfile to the "compiler" docker for "compilation", that is, the docker build command. The generated executable program is the image, and then we can run the image. This is the docker run command, and the image is the docker container when it runs.
The specific use methods are not described here. You can refer to the official document of docker, where there is a detailed explanation.
actual combat
docker common instructions
docker pull # Get docker image docker run -p... #Run container port mapping docker run -v xxx(local path):xxx(docker Internal directory)# Directory mount docker run -it # -The t option allows Docker to assign a pseudo TTY and bind it to the standard input of the container, - i keeps the standard input of the container open. docker commit # Save changes to a new image docker build # Create docker image docker create # docker attach # Enter container (not image) docker rm [docker id] # Delete docker container docker rmi [docker image id] # Delete docker image docker ps # View running docker s docker ps -a # View docker running history docker images # View the existing local docker image docker inspect # View image internal details docker cp # Copy files between host and container docker stop # Stop container docker search # Search for images in the remote warehouse docker hub docker login # Log in to docker hub docker push # Upload the local image to the docker hub
build custom docker
In addition to using the docker commit command, you can also write a Dockerfile (commonly known as this writing method) to define and save your own docker.
FROM xxx # Set base mirror MAINTAINER xxxx # Famous document author / maintainer RUN xxx # Execute command COPY xxx # Copy file ADD xxx # Add file ENTRYPOINT xxx # Specify the execution entry for the container EXPOSE xxx # Exposed port CMD xxx # Execute the command and specify the execution entry for the container WORKDIR # Specifies the path to run the command ENV # Set environment variables for the environment in the container USER # Specifies the user who executes the container VOLUME # Specifies the volume on which the container hangs when it executes
Each line in the Dockerfile generates a new layer, that is, each line of commands will generate a new docker id.
Docker image provides a convenient environment for the deep learning training model. Users can build their own arbitrary environment without affecting the system environment. Here is the basic docker environment construction process.
- Task requirements: for example, I want to work in torch 1 Based on the docker of 7 (hereinafter referred to as base docker), install some packages you want to install to build a new docker.
- General logic: first pull the desired base docker locally, enter the docker locally, and then install the package you want in the docker. After all the packages are installed, exit the current docker, commit the docker to a new docker (your own docker), and then push your docker to the dockerhub repo.
- Specific steps:
1) Go to the dockerhub and find a torch 1 7 docker, pull down, for example, from torch official docker tags Find the torch 1 we want in it 7 development version. Once found, run locally:
docker pull pytorch/pytorch:1.7.1-cuda11.0-cudnn8-devel
The above operation is to pull the docker locally first.
2) Enter docker:
docker run --runtime=nvidia -it --name=test --ipc=host --net=host pytorch/pytorch:1.7.1-cuda11.0-cudnn8-devel
3) After entering docker, you can configure your environment to your heart's content.
4) After configuration, "exit" exits docker.
5) Commit the configured docker to your own docker (equivalent to copying a copy to your own docker).
docker ps -a # View and find the id of the configured docker docker commit [docker id] geekyutao/foresee-rl:v0 # Geekyutao / forestee RL: V0 is the repo I created on dockerhub myself
6) Log in to the dockerhub locally, and then push your local docker to the dockerhub.
docker login -u [username] -p [password] # If an error is reported, it is likely that the machine uses a docker certificate by default # If an error is reported: delete the docker certificate under / usr/local/bin / and log in again # sudo rm /usr/local/bin/docker-credential-pass docker push geekyutao/foresee-rl:v0
7) Done! Delete the docker and docker image left during the operation. (basic operation with docker)

image