Docker Compose is a tool for running multi-container applications on Docker defined using the Compose file format. A Compose file is used to define how one or more containers that make up your application are configured. Once you have a Compose file, you can create and start your application with a single command: docker compose up, A commpose file defines your application, a componse file has several services, each service is one container!
You can imagine docker compose as a wrapper for docker command but supports operating containers at application level, meaning start/stop application, no matter how many container it has, it just makes the work earlier.
docker compose vs docker-compose: docker-compose is orignal tool this the target mentioned above, but docker-compose is written in Python while most Docker developments are in Go, so they decided to recreate docker compose project in Go with the same and more features, docker compose will eventually replace docker-compose, but no timeline for that yet, so if you’r new to this, use docker compose.
Define and run multi-container applications with Docker.
Options: --dry-run Execute command in dry run mode -f, --file stringArray Compose configuration files ...
Commands: build Build or rebuild services config Parse, resolve and render compose file in canonical format cp Copy files/folders between a service container and the local filesystem create Creates containers for a service. down Stop and remove containers, networks events Receive real time events from containers. exec Execute a command in a running container. images List images used by the created containers kill Force stop service containers. logs View output from containers ls List running compose projects 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 service containers rm Removes stopped service containers run Run a one-off command on 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
$ls docker-compose.yml Dockerfile $cat Dockerfile FROM hello-world
$cat docker-compose.yml version: '2' services: hello_world: # build this container from image directly image: hello-world hello-world-local: # build this container from Dockerfile build: context: .
$docker compose ls -a NAME STATUS CONFIG FILES compose exited(2) /tmp/compose/docker-compose.yml $docker compose ps -a NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS compose-hello-world-local-1 compose-hello-world-local "/hello" hello-world-local About a minute ago Exited (0) About a minute ago compose-hello_world-1 hello-world "/hello" hello_world About a minute ago Exited (0) About a minute ago