DOCKER study notes - common commands

1. In order to avoid using a privileged identity every time you use docker, you can add the current user to the docker user group

2. docker rmi image:tag delete image, -f force delete

docker rmi imageId is also deleted

docker rm containerId delete container

3. docker ps -a View all containers that exist on the machine

4. How to create an image:

(1) Create a docker commit based on an existing mirrored container 

(2) Import docker import based on the local template 

5. docker inspect image/container id: Get the metadata of the image or container

6. docker run creates and starts the container: the -d parameter runs the container in the background; the -v parameter creates a data volume in the container

docker stop container id: terminate the container, docker start starts the container

docker exec -it container id: enter the container

docker logs -f container id : View container logs

docker run : create a new container and run a command

grammar

docker run [OPTIONS] IMAGE [COMMAND][ARG...] 

OPTIONS Description:

  • -a stdin:  Specify the content type of standard input and output, and three items of STDIN/STDOUT/STDERR are optional;

  • -d:  run the container in the background and return the container ID;

  • -i:  run the container in interactive mode, usually used with -t;

  • -t:  reallocate a pseudo input terminal for the container, usually used at the same time as -i;

  • --name="nginx-lb":  Specify a name for the container;

  • --dns 8.8.8.8:  Specify the DNS server used by the container, the default is the same as the host;

  • --dns-search example.com:  Specify the container DNS search domain name, the default is the same as the host;

  • -h "mars":  specifies the hostname of the container;

  • -e username="ritchie":  set environment variables;

  • --env-file=[]:  Read environment variables from the specified file;

  • --cpuset="0-2" or --cpuset="0,1,2":  Bind the container to the specified CPU to run;

  • -m : Set the maximum memory used by the container;

  • --net="bridge":  Specify the network connection type of the container, support bridge/host/none/container: four types;

  • --link=[]:  add a link to another container;

  • --expose=[]:  open a port or a group of ports;


7. docker export exports the container docker import imports the container

8. docker ps:  List containers

grammar

docker ps [OPTIONS]

OPTIONS Description:

  • -a : Show all containers, including not running ones.

  • -f :根据条件过滤显示的内容。

  • --format :指定返回值的模板文件。

  • -l :显示最近创建的容器。

  • -n :列出最近创建的n个容器。

  • --no-trunc :不截断输出。

  • -q :静默模式,只显示容器编号。

  • -s :显示总的文件大小。

9、 docker port 容器名称 : 查看端口映射

10、docker exec -it 容器id bash 进入容器内部

docker exec -it itbilu-mysql bash

11、docker logs -f 容器id : 查看容器日志

12、docker rm $(docker ps -a -q) : 删除所有容器

docker rm $(docker ps | grep "athena" | awk  ' {print $1}' )  查出名称包含athena的,取第一列(id列)

13、docker ps -s 查看各个容器占用空间大小。

14、docker system df查看Docker的磁盘使用情况

15、docker system prune命令可以用于清理磁盘,删除关闭的容器、无用的数据卷和网络,以及dangling镜像(即无tag的镜像)。docker system prune -a命令清理得更加彻底,可以将没有容器使用Docker镜像都删掉。

16、docker-compose logs:查看所有容器的日志

17、docker stats查看各个容器的cpu和内存利用率

18、apt-get remove docker-ce  卸载docker-ce

        rm -rf /var/lib/docker  : 删除镜像、容器、存储卷

      sudo rm /usr/local/bin/docker-compose 卸载docker-compose

19、从宿主机拷文件到容器里面

      在宿主机里面执行如下命令:docker cp 要拷贝的文件路径 容器名:要拷贝到容器里面对应的路径

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325442083&siteId=291194637