Images
Image: just like OS image, can be used to create a container.
Create image by:
.tar
file, withdocker load -i <tar_file>
command.Dockerfile
script, withdocker build -t
command.
List images: Use docker images
to show all available images on the device.
Container
Container: An instance running the OS. built from image.
Create from image by docker run
command. You can pass in some configuration. (Note some config are fixed after creation. Be careful!) Some common parameters are shown below:
1 | docker run -it -d -p <localport>:<dockerport> --gpus all --name <name> --volume </path/host/directory>:</path/container/directory> <IMAGE ID> |
-d
means “detach”, running the docker container in the backend.-p <hostport>:<dockerport>
means forward the docker’s port<dockerport>
to the host machine’s port<hostport>
. Usually, we forward22
port from container to e.g.,2222
port in host for ssh connection.--gpus all
means all host’s GPU are visible to the container.--name <name>
indicates the name of the container. It will be shown in thedocker ps
and other places.--volume </path/host/directory>:</path/container/directory>
indicates which host directory are shared with container’s directory, therefore, you can access it in both the container and host.<IMAGE ID>
is the id of the image to be built.
List containers: Use docker ps -a
to check status of all containers. Use docker ps
to check all running containers.
Three ways to interact with the container:
- Docker desktop’s shell
docker exec -it <container id> bash
- SSH, if you have set so
Start the container: By docker start <CONTAINER ID>
, or do it in docker desktop.
Stop the container: By docker stop <CONTAINER ID>
, or do it in docker desktop.
More info: please see the official cheat sheet at here.