some basic concepts
What is an image file?
Docker packages the application and its dependencies in an image file. Only through this file can a Docker container be generated. The image file can be seen as a template for the container. Docker generates instances of containers based on image files. The same image file can generate multiple container instances running at the same time.
image is a binary file. In actual development, an image file is often generated by inheriting another image file and adding some personalized settings. For example, you can add an Apache server to the Ubuntu image to form your image.
The image file is universal, and the image file of one machine can be copied to another machine, and it can still be used. Generally speaking, in order to save time, we should try to use image files made by others instead of making them ourselves. Even if it needs to be customized, it should be processed based on other people's image files, not from scratch.
For the convenience of sharing, after the image file is created, it can be uploaded to the online warehouse. Docker's official warehouse Docker Hub is the most important and most commonly used image warehouse. In addition, it is also possible to sell the image files you make yourself.
View the loaded image on this machine
docker images
What container file?
The container instance generated by the image file is itself a file called a container file. That is, once the container is generated, two files will exist at the same time: the image file and the container file. And closing the container does not delete the container files, it just stops the container from running.
Running the image file will generate a container file:
docker run -it <image_name> /bin/bash
List running containers:
docker ps
List all containers on the machine, including terminated containers
docker ps -a
Common commands
docker load docker image as non-root
1. Docker requires users to have sudo authority. In order to avoid typing every command sudo
, users can be added to the Docker user group
sudo usermod -aG docker <username>
2. Restart the computer
3. Unzip the image file (i.e. image file) and load the image as a user
docker load --input /home/developer/rknn-toolkit/rknn-toolkit-1.7.1-docker.tar.gz
After loading the image, it will be saved in the overlay2 folder in the /var/lib/docker directory, so if your / partition is too small, remember to delete unnecessary images frequently
4. Check whether the image has been loaded
root@lrj-HLY-WX9XX:/var/lib/docker# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rknn-toolkit 1.7.3 9cce319ebc29 11 months ago 3.7GB
5. rknn-toolkit:1.7.3
Open an interactive shell in the container based on the image, and give the container sufficient permissions to access the host's USB device and file system in the container. By mounting the host's /dev/bus/usb/
and /home/lrj/work/rv1126/model_convert/
directories to the container's /dev/bus/usb/
and /test
directories, the sharing of devices and files between the host and the container is realized
docker run -t -i --privileged -v /dev/bus/usb/:/dev/bus/usb -v /home/lrj/work/rv1126/model_convert/:/test rknn-toolkit:1.7.3 /bin/bash
-
docker run
: Start a new container. -
-t
: Allocate a pseudo-terminal (pseudo-TTY) for the container. -
-i
: Keep the container open with an interactive command line. -
--privileged
: Give the container privileges to allow operations on the host device. -
-v /dev/bus/usb/:/dev/bus/usb
: Mount the host's/dev/bus/usb/
directory to the container's/dev/bus/usb/
directory to share access to USB devices between the host and the container. -
-v /home/lrj/work/rv1126/model_convert/:/test
: Mount the directory on the host/home/lrj/work/rv1126/model_convert/
to the directory in the container/test
to share files between the host and the container. -
rknn-toolkit:1.7.3
: The name of the running container image and its version number. -
/bin/bash
: A command to run immediately after the container starts. Here is the command line to open the container as an interactive shell.
How to delete mirror?
Before deleting an image, you must stop the running container of the image and delete the container; then you can delete the image
docker stop <container_ID> && docker rm <container_ID> && docker rmi <image_name>
How to interactively enter a stopped container?
Start the container first
docker start <container_ID>
Then enter the container interactively
docker exec -it <container_ID> /bin/bash