Docker

1 minute read

General Command of Docker

# create volume
docker volume create myvol

# pull image from cloud/hub
docker pull [user]/image

# build docker image tagged by -t with dockerfile in directory 
docker build -t myimage "X:\MyDirWithDockerfile\"

# run iterativelly with tty /bin/bash as root user using docker image as container
docker run -it "myimagename or myimageid" /bin/bash
## example: docker run interactive image adc7e1e17105 with /bin/bash
docker run -it adc7e1e17105 /bin/bash

# to resume after exit:
## first check id with
docker ps -a
## then use "id" to resume without "" 
docker start -a -i "id"

# issue when doing: RUN ...build.sh
## solution based on (https://github.com/docker/for-win/issues/1166) is to:
before RUN ...build.sh, add a:
RUN chmod +x ...build.sh

# pushing image to cloud
docker login
docker tag myimage [user]/myimage
docker push [user]/myimage

Docker Specifics About Run


# docker run /bin/bash in myimage 
docker run -it myimage /bin/bash

## ... as user myuser  
docker run -it -u myuser myimage /bin/bash

## ... with volume myvolume in ...
### ... /home/myvolume
docker run -it -u myuser -v myvolume:/home/myvolume
### ... /myvolume
docker run -it -v myvolume:/myvolume

# connect to already run myimage
docker start -ia (docker ps -a | grep myimage | awk '{print $1;}')

Docker Specifics About Removal


# remove containers manually
## first get id of our containers (docker container ls - do not work somehow...)
docker ps -a
## now remove by our id (without "")
docker rm "id"

# docker remove all containers
docker rm $(docker ps -a -q)

# remove first from specific containers with mycontainer word in name
 docker rm (docker ps -a | grep mycontainer | awk '{print $1;}')

# remove images with <none> name and force it (usually remove all images -.-)
docker rmi $(docker images -f "dangling=true" -q) -f

Categories:

Updated: