docker configure, not use sudo:
adduser <user name> docker
sudo chmod 666 /var/run/docker.sock
docker build, give the image a tag name:
docker build -t <tag name> .
example:
docker build -t ubuntu .
docker run:
docker run -t <tag name>
docker run in detach mode:
docker run -d <tag name>
docker run in detach mode, and bash wait in background:
docker run -t -d <tag name>
docker run, give the container a name:
docker run --name <container name> <tag name>
docker run, enter bash:
docker run -t -d --name <container name> <tag name>
docker exec -t -i <container name> /bin/bash
example:
docker run -t -d --name ubuntu ubuntu:18.04
docker exec -t -i ubuntu /bin/bash
view all container and images:
docker ps -a && docker images -a
remove all containers:
docker rm $(docker ps -aq)
remove all images:
docker rmi $(docker images -q)
remove named container:
docker container rm <container name>
volume create :
docker volume create <volumn name>
docker volume inspect <volumn name>
volume --mount:
docker run --mount source=<volume name>,target=/usr/src/myapp <tag name>
volume --volume:
docker run --volume ~/Desktop/docker/docker_volume:/usr/src/ <tag name>
(failed to check files in ~/Desktop/docker/docker_volume)
volume check:
docker volume ls
volume visit:
cd /var/lib/docker/volumes/dockerVolume/_data
volume rm:
docker volume rm <volumn name>
reference:
https://stackoverflow.com/questions/30209776/docker-container-will-automatically-stop-after-docker-run-d