:four_leaf_clover:碎碎念:four_leaf_clover:
Hello米娜桑,这里是英国留学中的杨丝儿。我的博客的关键词集中在算法、机器人、人工智能、数学等等,点个关注吧,持续高质量输出中。
:cherry_blossom:唠嗑QQ群:兔叽的魔术工房 (942848525)
:star:B站账号:杨丝儿今天也在科学修仙(UP主跨站求个关注)
:star2:docker中容器和镜像的关系
Docker 包括三个基本概念:
- 镜像(Image):Docker 镜像(Image),就相当于是一个 root 文件系统。比如官方镜像 ubuntu:16.04 就包含了完整的一套 Ubuntu16.04 最小系统的 root 文件系统。
- 容器(Container):镜像(Image)和容器(Container)的关系,就像是面向对象程序设计中的类和实例一样,镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。
- 仓库(Repository):仓库可看成一个代码控制中心,用来保存镜像。
:star2:镜像操作
1 | # 存在有Dockerfile的docker文件夹 |
:star2:容器操作
1 | # 创建容器 |
:star2:补充
1 | # 如果权限不够可以使用sudo,也可以采用 |
:star2:参考
- 菜鸟教程
- tldr仓库
docker
Manage Docker containers and images.
Some subcommands such asdocker run
have their own usage documentation.
More information: https://docs.docker.com/engine/reference/commandline/cli/.
List all docker containers (running and stopped):
docker ps --all
Start a container from an image, with a custom name:
docker run --name container_name image
Start or stop an existing container:
docker start|stop container_name
Pull an image from a docker registry:
docker pull image
Display the list of already downloaded images:
docker images
Open a shell inside a running container:
docker exec -it container_name sh
Remove a stopped container:
docker rm container_name
Fetch and follow the logs of a container:
docker logs -f container_name
docker run
Run a command in a new Docker container.
More information: https://docs.docker.com/engine/reference/commandline/run/.
Run command in a new container from a tagged image:
docker run image:tag command
Run command in a new container in background and display its ID:
docker run -d image command
Run command in a one-off container in interactive mode and pseudo-TTY:
docker run --rm -it image command
Run command in a new container with passed environment variables:
docker run -e 'variable=value' -e variable image command
Run command in a new container with bind mounted volumes:
docker run -v path/to/host_path:path/to/container_path image command
Run command in a new container with published ports:
docker run -p host_port:container_port image command
Run command in a new container overwriting the entrypoint of the image:
docker run --entrypoint command image
Run command in a new container connecting it to a network:
docker run --network network image