Playing With Docker Container - Commands
Playing With Docker Container - Commands
Do
For Containers :
docker stop $(docker ps -qa)
docker rm $(docker ps -qa)
For Images :
dockemi $(docker images -qa)
docker images
docker rmi -f b00ea124ed62 529165268aa2 0c45f7936948
docker images
Docker run :
--privileged
$ docker run -t -i --rm ubuntu bash
root@bc338942ef20:/# mount -t tmpfs none /mnt
mount: permission denied
$ docker run -t -i --privileged ubuntu bash
root@50e3f57e16e6:/# mount -t tmpfs none /mnt
root@50e3f57e16e6:/# df -h
Filesystem Size Used Avail Use%
Mounted on
none 1.9G 0 1.9G 0% /mnt
-w
$ docker run -w /path/to/dir/ -i -t ubuntu pwd
The -w lets the command being executed inside directory given, here
/path/to/dir/.
Note : If the path does not exist it is created inside the container.
$ docker run --env VAR1=value1 --env VAR2=value2 ubuntu env | grep VAR
VAR1=value1
VAR2=value2
Limiting Memory
$ docker run -d -p 8081:80 --memory=20m --memory-swap=20m nginx
$ docker container run -d --memory-reservation=250m --name mymem1
alpine:3.8 sleep 3600
Limiting CPU
--cpus
Docker 1.13 and higher:
$ docker run -it --cpus=".5" ubuntu /bin/bash
Copy :
Logs :
$ docker logs 779eb8148aa7 --follow