关于docker-compose与docker
docker-compose是docker 之上的应用,也就是说脱离不开docker。与docker一样,有命令和配置文件。
docker的命令是:
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
docker-compose的命令是:
Commands:
build Build or rebuild services
bundle Generate a Docker bundle from the Compose file
config Validate and view the Compose file
create Create services
down Stop and remove containers, networks, images, and volumes
events Receive real time events from containers
exec Execute a command in a running container
help Get help on a command
images List images
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pull service images
push Push service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
top Display the running processes
unpause Unpause services
up Create and start containers
version Show the Docker-Compose version information
命令使用上有区别,使用的时候注意下即可。接下来是文件
docker用:
Dockerfile
docker-compose用:
docker-compose.yml #值得注意,yml的格式非常严格,一点不能错
关系就是:
docker-compose.yml配置的是编译Dockerfile或者运行images或者启动关闭容器的运行参数,比如卷,网卡等等。
换句话说,Dockerfile还是独立存在的,docker-compose.yml构建镜像配置中需要指明Dockerfile的位置。
docker-compose 简单示例
docker-compose的安装是独立于docker的,怎么安装自己去网上或者官网找
https://docs.docker.com/compose/
创建Dockerfile文件,并写入
FROM centos
RUN ls / > name.txt
创建docker-compose.yml文件,并写入
version: '3'
services:
os:
build: .
注意:冒号后面必须空一格,再写内容,示例中的两个文件放在同一个路径
当前路径下,docker-compose up就可以了,后面直接查看
1。

2。

3。

docker-compose会自动给容器命名–当前目录名+服务名+序号–注意services(服务名)是在yml文件中自定义的,删除容器的时候,不能用容器名,要用服务名。
4。

docker-compose搞不定某个镜像或者容器,换docker处理便是
唠叨
关于docker入门也要学很多:
docker 命令
dockerfile语法 --重要
docker-compose命令
docker-compose.yml语法 --重要
理解其中的关系 --难找
关于网卡和虚拟网卡(vth)–难找 重要
目标docker应用
----------这只是入门,会用的程度 也是核心
本文深入解析Docker与docker-compose的区别与联系,包括各自的命令、配置文件及使用场景。详细介绍了Dockerfile与docker-compose.yml的语法,以及如何通过docker-compose进行容器编排,实现服务的快速部署。
7218

被折叠的 条评论
为什么被折叠?



