Docker Command - Massii94/GENERAL-TUTORIAL GitHub Wiki

list docker local images
sudo docker images
run container
sudo docker run mozilla
run docker interactive with terminal
sudo docker run -it mozilla
dist docker containers
my@my-pc:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8e67937e3f76 mozilla "/bin/bash" 26 minutes ago Up 26 minutes 0.0.0.0:5002->5002/tcp amazing_payne
loading image:
docker load < busybox.tar.gz
mount external address to /srv in docker storage:
--mount type=bind,source=$HOME,target=/mounted
sudo docker run -it --mount type=bind,source=/home/usr/Desktop/app,target=/srv mozilla
run multiple terminal with same container
docker exec -it <container> bash
run with gui support
xhost local:root
sudo docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw --mount type=bind,source=/home/usr/Desktop/app,target=/srv mozilla
resize shared memory
--shm-size 8G
make docker image from docker file wuth custom image name
mkdir dockerdir
nano dockerdir/dockerfile
write these into file and save changes
FROM labelimage:latest as base
run this command
docker build -t image_name dockerdir/
# Run Docker commands without sudo
##### 1. Add the `docker` group if it doesn't already exist
```console
$ sudo groupadd docker
Optionally change the username to match your preferred user.
$ sudo gpasswd -a $USER docker$ sudo service docker restartIf you are on Ubuntu 14.04-15.10, use docker.io instead:
$ sudo service docker.io restart$ sudo docker commit [container_id] [new_image_name]$ sudo docker save myimage:latest | gzip > myimage_latest.tar.gz$ sudo nvidia-docker run -it myimage:latestImport/Export container
Import a container as an image from file:
cat my_container.tar.gz | docker import - my_image:my_tag
Export an existing container:
docker export my_container | gzip > my_container.tar.gz
Difference between loading a saved image and importing an exported container as an image
Loading an image using the load command creates a new image including its history. Importing a container as an image using the import command creates a new image excluding the history which results in a smaller image size compared to loading an image.
docker rm $(docker ps -a -q)
how to set special IP to our docker container:
First creat a network:
docker network create --subnet=192.168.1.1/16 mynet
Then run the container:
docker run --net mynet123 --ip 192.168.1.2 (***you can put 3 or 4 or ... instead of 2) -it docker_image_name
1-install vcxsrv
open up windows PowerShell and use these commands:
set-variable -name DISPLAY -value 172.16.2.155:0.0
docker run -ti --rm -e DISPLAY=$DISPLAY nvidia/cuda:10.2-devel-ubuntu18.04
nvidia docker start error
sudo apt install nvidia-docker2:amd64=2.5.0-1 \
libnvidia-container-tools:amd64=1.3.3-1 \
nvidia-container-runtime:amd64=3.4.2-1 \
libnvidia-container1:amd64=1.3.3-1 \
nvidia-container-toolkit:amd64=1.4.2-1
references: https://github.com/wsargent/docker-cheat-sheet https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes