[Docker] $ 1_ container management

Docker container management

docker command

1. Check System Information

$ docker info
$ docker system info

2.Managment Commands

# 创建一个新的容器,下面分别为 Commands 和 Management Commands,作用相同
$ docker create
$ docker container create

# 显示容器列表
$ docker ps
$ docker container ls

# 在一个新的容器中运行一个命令
$ docker run
$ docker container run

Lifecycle container management

1. Create a container

# Management Commands
$ docker container run [OPTIONS] IMAGE [COMMAND [ARGS...]]
  • -i or --interactive, interactive mode

  • -t or --tty, assigned a pseudo-TTY, i.e., pseudo-terminal

  • -rm automatically removed after the container exit

  • -p mapped to the host port of the container

  • -v or --volume, the specified data volume

$ docker container run  busybox echo "hello docker"
    

$ docker container run \
    -i -t \
    ubuntu /bin/bash

/// 以后台模式创建并运行一个容器
$ docker container run \
    -i -t -d \
    ubuntu /bin/bash

# Management Commands
$ docker container create [OPTIONS] IMAGE [COMMAND] [ARG...]
  • When a container is specified -name name is not specified, it will generate a random name

  • -hostname container set host name

  • -mac-address set the MAC address

  • -ulimit set Ulimit options

$ docker container create \
    --name shiyanlou01 \
    --hostname shiyanlou01 \
    --mac-address 00:01:02:03:04:05 \
    --ulimit nproc=1024:2048 \
    -it ubuntu /bin/bash

2. Start and stop container

# Management Commands $ docker container start [OPTIONS] CONTAINER [CONTAINER...]

# 创建
$ docker container create \
    --name shiyanlou01 \
    --hostname shiyanlou01 \
    --mac-address 00:01:02:03:04:05 \
    --ulimit nproc=1024:2048 \
    -it ubuntu /bin/bash

# 启动
$ docker container start shiyanlou01

# 直接启动
$ docker container run \
    --name shiyanlou01 \
    --hostname shiyanlou01 \
    --mac-address 00:01:02:03:04:05 \
    --ulimit nproc=1024:2048 \
    -it ubuntu /bin/bash

# Management Commands $ docker container stop CONTAINER [CONTAINER...]


# Management Commands $ docker container restart CONTAINER [CONTAINER...]

3. Pause and resume the process of

# Management Commands $ docker container pause CONTAINER [CONTAINER...]

# Management Commands $ docker container unpause CONTAINER [CONTAINER...]

4. Review the list of containers

# Management Commands $ docker container ls [OPTIONS]

$ docker container ls
$ docker container ls -a -s

The container is connected to the running

# Management Commands $ docker container attach [OPTIONS] CONTAINER

$ docker container start shiyanlou01

$ docker container attach shiyanlou01

6. See metadata container

# Management Commands $ docker container inspect [OPTIONS] CONTAINER [CONTAINER...]

# 使用容器名
$ docker container inspect shiyanlou01

7. The container log management

# Management Commands $ docker container logs [OPTIONS] CONTAINER

  • -t timestamp display or --timestamps

  • -f output in real time, similar to the tail -f

8. The process of information display container

# Management Commands $ docker container top CONTAINER

9. Check the file modified

# Management Commands $ docker container diff CONTAINER

10. The container Run

$ docker container exec shiyanlou01 echo "test_exec"

11. Delete the container

Management Commands

$ docker container rm [OPTIONS] CONTAINER [CONTAINER...]

#如果想删除之前创建的所有容器,可以使用以下命令:
$ docker container rm -f $(docker container ls -aq)

Published 78 original articles · won praise 0 · Views 1435

Guess you like

Origin blog.csdn.net/qq_30782921/article/details/101625934