Follow this to get a good command of Docker usage.
Basic Commands
The Reference documentation | Docker Docs gives the most complete guidance.
But here, only swift commnads listed which are sufficient for general using.
BTW I documented how to run a mysql docker container in First how-to-do note, including initial steps.
Run the Container
Docker can be used as microservice, while for non-professional developers, we use it as lightweight virtual machine.
1 | $ docker run -itd image_name /bin/bash |
Migrate Images and Containers
To migrate images, use save
and load
.
First save the image:
1 | $ docker save -o image.tar image_id_or_image_name |
Then load the image:
1 | $ docker load -i image.tar |
New image name stays the same with the old one.
To migrate containers, use export
and import
.
First export the container:
1 | $ docker export container_id_or_container_name > container.tar |
Then import the container:
1 | $ docker import - new_container_name < container.tar |
You see, you can name the new image this step.
Get GPU support from Nvidia
Check this out: Installing the NVIDIA Container Toolkit for updated installation.
First to figure out the differences between: nvidia-docker
, nvidia-docker2
and nvidia-container-toolkits
.
The nvidia-docker
and nvidia-docker2
are archived(Dec 6, 2023) old repos.
In nvidia-docker
age it can be runned by
1 | $ nvidia-docker run XXX |
In nvidia-docker2
the above nvidia-docker
command is equal to:
1 | $ docker run --runtime=nvidia XXX |
The relationship between these methods:
1 | Backward compatibility To help transitioning code from 1.0 to 2.0, a bash script is provided in /usr/bin/nvidia-docker for backward compatibility. It will automatically inject the --runtime=nvidia argument and convert NV_GPU to NVIDIA_VISIBLE_DEVICES. |
Up to now, NVIDIA Container Toolkit is the latest solution, as the sample usage goes like:
1 | $ sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi |
Then output panel is like
1 | +-----------------------------------------------------------------------------+ |
The --runtime=nvidia
can be omitted, while the --gpus all
is essential.
The ubuntu
image here can be replaced with images listed on Nvidia CUDA Linux Container Image Supported tags.
Then process as the doc goes.