How to pull docker image and run it— useful commands and some tips

Bo Li
2 min readMar 29, 2023

--

Pulling a docker image from docker hub is simple. It is very recommended to push your docker image to docker hub as other people can reuse it without the compatibility issues of soft package. Building old docker files can be very painful sometimes.

Once done, use either ‘docker images’ or ‘docker image list’ to check the existence with the presence of image ID , which you will need if you want to remove it.

docker images
docker image list

All the files you saved in docker image will disappear in the next run, so it would be wise to create and mount a docker volume so that you don’t need to docker copy data each time. Below create a docker volume called ‘discobox_dir’ and list all the volumes.

docker volume create discobox_dir
docker volume list

Now run the docker images with mounting the docker volume. I need large share memory (12GB) for the data loader in deep learning model training, so this needs to be specified in the arguments. In the docker environment, you will find a folder called Discobox in /workspace. It would be safe to copy and paste data there.

docker run -it -v discobox_dirs:/workspace/Discobox --shm-size 12g docker.io/voidrank/discobox:latest

You can copy data from local to docker volume by:

docker cp c:\myfolder\myfile.txt dummy:/root/myfile.txt

To clarify the difference between docker image and docker container: Docker image can exist after running ‘docker build’, but docker container exists with only ‘docker run’. Docker container is a runtime instance of a Docker image. Docker container cannot exist without docker image.

To stop a docker container, simply find the running docker container ID by

docker ps

or

docker container list

and run

docker stop 'docker container ID'

To remove unwanted docker images, run

docker image rm 'image ID'

You are good to go!

--

--

Bo Li
Bo Li

Written by Bo Li

Plant phenotyping, Computer vision and Machine learning

No responses yet