慎独
慎独
文章目录
  1. someUser don’t need root
  2. stop docker container
  3. export single file from runing container
  4. delete force or not
  5. remove all stoped container
  6. kill containers and remove them:
  7. remove all images
  8. mount the directory to docker
  9. link container
  10. docker expose port

Docker for daily use

1
2
$ docker run -i -t --name alias_container_name images_name 
$ docker attach container_id

someUser don’t need root

sudo usermod -aG docker someUser

stop docker container

$ docker stop container_id

export single file from runing container

1
2
$ docker cp name.txt container_name:/name.txt
$ docker cp container_name:/name.txt name.txt

delete force or not

1
2
3
$ docker rm container
$ docker rmi images
$ dcoker rmi -f images | docker rm -f container_id

remove all stoped container

$ docker rm $(docker ps -a -q)

kill containers and remove them:

$ docker rm $(docker kill $(docker ps -aq))

remove all images

$ docker rmi $(docker images -qf "dangling=true")

docker rmi $(docker images | grep -v 'ubuntu\|my-image' | awk {'print $3'})

mount the directory to docker

$ docker run -d P --name mnistDemo -v .:/mnistDemo caffe:latest /bin/bash

docker run -i -t --name container1 --net=my-network --net-alias=container1 ubuntu:trusty /bin/bash

docker expose port

$ docker run -d -p 80:80 my_image service nginx start

References:

支持一下
三思而后行