查看镜像内容

1
docker run -it image_name sh

参考链接: Stackoverflow - How to see docker image contents

自动拉起

1
docker run -d --restart=unless-stopped image_name

参考链接: Start containers automatically

删除镜像

1
2
# 删除未被使用的镜像
docker image prune -a -f
1
2
3
4
5
6
7
8
9
10
docker image prune --help

Usage: docker image prune [OPTIONS]

Remove unused images

Options:
-a, --all Remove all unused images, not just dangling ones
--filter filter Provide filter values (e.g. 'until=<timestamp>')
-f, --force Do not prompt for confirmation

容器相关操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 查看运行中的容器
docker ps

# 查看所有容器(包括已停止的)
docker ps -a

# 启动容器
docker run image_name

# 启动一个已停止的容器
docker start container_name

# 停止容器
docker stop container_name

# 删除容器
docker rm container_name

# 查看容器日志
docker logs container_name
1
2
# 进入容器
docker exec -it container_name
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

Run a command in a running container

Options:
-d, --detach Detached mode: run command in the background
--detach-keys string Override the key sequence for detaching a
container
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
-i, --interactive Keep STDIN open even if not attached
--privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format:
<name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container