Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The Foundation of docker-compose (1)

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Docker-compose is a tool for defining and running multi-container Docker applications. With Compose, you can use YAML files to configure your application's services. Then, using a single command, you can create and start all services from the configuration.

The docker-compose step uses Dockerfile to define the environment of the application. Define the services that make up the application in docker-compose.yml. Run docker-compose up to start and run the entire application. Install compose to download the current stable version and grant execution permission sudo curl-L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname-s)-$(uname-m)"-o / usr/local/bin/docker-composesudo chmod + x / usr/local/bin/docker-compose to set the environment variable sudo ln-s / usr/local/bin/docker-compose / usr/bin/docker-compose# or: Vim / etc/profileexport COMPOSE=/usr/local/bin/export PATH=$COMPOSE:$PATH# execution: source / etc/profile takes effect. Update

Starting with version 1.3, Compose uses Docker tags to track containers and needs to recreate containers to add tags. If Compose detects a container created without a label, it will refuse to run.

Uninstall sudo rm / usr/local/bin/docker-compose# or: pip uninstall docker-composecompose command explain the build command Usage: build [options] [--build-arg key=val...] [SERVICE...] Options:-- compress uses gzip to compress the build context-- force-rm always removes intermediate containers-- do not use caching when no-cache builds an image-- pull pulls the latest version of the image-- m,-- memory MEM sets the memory limit for the build container-- build-arg key=val sets the variable for the service's build time-- parallel parallel build image.

Note: if you change the Dockerfile of the service, run docker-compose build to rebuild.

Bundle command Usage: bundle [options] option:-- push-images automatically pushes the image of the built service-o,-- output PATH writes the package file to the path config command Usage: config [options] option:-- tag of the resolve-image-digests image summary-- no-interpolate does not insert the environment variable-Q,-- quiet only verifies the configuration, does not print anything-- services prints the service name One per line-- volumes prints the storage volume name, one per line-- hash= "*" print service configuration hash, one per line. Set "service1,service2" to get a list of specified services or use wildcards to display all services. The create command creates a container for the service Usage: create [options] [SERVICE...] Option:-- force-recreate re-create the container even if the configuration has not been changed-- no-recreate do not recreate the container if the container already exists. -- no-build do not build an image even if the container is missing. -- build builds an image before creating a container. Down command Usage: down [options] option:-- rmi type to delete an image. Type: 'all': deletes all images used by any service. 'local': only deletes the custom tags of the images that are not set by the image field. -v,-- volumes deletes storage volumes declared in volumes-- remove-orphans deletes containers that do not have services defined in the file-t,-- timeout TIMEOUT specifies shutdown timeout in seconds (default is 10s)

What is deleted by default: the container of the service defined in the Compose file and the network of the defined service.

Note: networks and volumes defined as external will never be deleted.:

Events command Usage: events [options] [SERVICE...] Option:-- json outputs events to json object stream exec command Usage: exec [options] [- e KEY=VAL...] SERVICE COMMAND [ARGS...] Option:-d,-- detach runs the command in the background-- privileged provides extended permissions for the process-u,-- user USER runs the command-T as the user-T disables pseudo-tty allocation. By default, `docker-compose exec` assigns the index of the TTY--index=index container.-e,-env KEY=VAL sets the environment variable-w,-- workdir DIR the path of the workdir directory of this command images command Usage: images [options] [SERVICE...] Option:-Q,-- quiet displays only the IDkill command Usage: kill [options] [SERVICE...] Option:-s SIGNAL SIGNAL signal is sent to the container. The default signal is SIGKILL to force the container to stop by sending a SIGKILL signal: docker-compose kill-s SIGINTlogs command Usage: logs [options] [SERVICE...] Option:-- no-color produces monochrome output-f,-- follow displays timestamps according to log output-t,-- timestamps-- tail= "all" the number of lines displayed at the end of the log in each container pause command Usage: pause [SERVICE...] The container where the service is suspended: docker-compose unpauseport command Usage: port [options] SERVICE PRIVATE_PORT option:-- protocol=proto tcp or udp. The default is the index of the tcp--index=index container. PS command Usage: ps [options] [SERVICE...] Option:-Q,-- quiet displays only id--services display service-- filter KEY=VAL filter service by attribute-- a,-- all displays all stopped containers pull command Usage: pull [options] [SERVICE...]-- ignore when ignore-pull-failures pull image fails-- parallel parallel pull image-- no-parallel disables parallel pull image-Q -- quiet does not print progress information when pulling the image-- include-deps declares the service as a dependency push command Usage: push [options] [SERVICE...] Option:-- ignore the restart command Usage: restart [options] [SERVICE...] when ignore-push-failures push image fails Option:-t,-- timeout TIMEOUT specifies to close the timeout rm command in seconds Usage: rm [options] [SERVICE...] Option:-f,-- force do not ask whether to delete, force delete.-s,-- stop stops the container before removal-v delete storage volumes attached to the container list all volumes, use docker volume ls. Any data that is not in the volume is lost. Delete the stopped service container. By default, storage volumes attached to the container are not deleted. The run command Usage: run [options] [- v VOLUME...] [- p PORT...] [- e KEY=VAL...] [- l KEY=VALUE...] SERVICE [COMMAND] [ARGS...] Option:-d,-- detach runs the container in the background Print the new container name-name NAME specifies the name for the container-entrypoint CMD overrides the entry point of the image-e KEY=VAL sets the environment variable-l,-label KEY=VAL adds or overrides the tag (can be used multiple times)-u,-- user= "" runs with the specified user name or uid-- no-deps does not start dependent services-- delete container-p after rm runs -- publish= [] publishes the port of the container to the host-- service-ports runs commands to the host with the service port enabled and mapped.-- use-aliases uses the network alias of the service in the network-v,-- volume= [] binds a storage volume-w The working directory in the workdir= "" container for example: docker-compose run-- service-ports web python manage.py shelldocker-compose run-- publish 8080 publish 8022 publish 22-p 127.0.1 service-ports web python manage.py shelldocker-compose run 2021 web python manage.py shelldocker-compose run db psql-h db-U dockerdocker-compose run-- no-deps web python manage.py shellscale command Please use the up command with the-- scale flag. Usage: scale [options] [SERVICE=NUM...] Option:-t,-- timeout TIMEOUT specifies the number of containers to run for the service with the shutdown timeout set in seconds. Numbers are specified as parameters in the form service = num: docker-compose scale web=2 worker=3start command Usage: start [SERVICE...] The existing container stop command to start the service Usage: stop [options] [SERVICE...]-t,-- timeout TIMEOUT specifies the shutdown timeout top command Usage: top [SERVICE...] in seconds Displays the running process .unpause command Usage: unpause [SERVICE...] Cancel the paused container up command Usage: up [options] [--scale SERVICE=NUM...] [SERVICE...] Option:-d,-- detach runs the container in the background, prints a new container name-- no-color produces monochrome output-- quiet-pull pulls without printing progress information-- no-deps does not start other services that depend on this service-- force-recreate recreates the container even if it is configured-- always-recreate-deps recreates the dependent container-- no-recreate if the container already exists Do not create.-- do not build an image even if no-build is lost.-- do not start the service after the no-start is created-- build builds the image before starting the container-- abort-on-container-exit if any containers stop. Then stop all containers-t,-- timeout TIMEOUT close when using this timeout (in seconds) to connect containers or containers. -V,-- renew-anon-volumes recreates the storage volume without retrieving data from previous containers.-- remove-orphans deletes containers for undefined services-- exit-code-from SERVICE returns the exit code for the selected service-- scale SERVICE=NUM extends SERVICE to NUM instances

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report