Docker-Compose: is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
Need to good to yml file directory to successfully run the docker-compose commands.
docker-compose start wordpress_db :it will only start 1 service
but docker-compose start : will start all the services
similar is the case with other commands.
Starts an existing service container.
specify a shutdown timeout in seconds.(default: 10)
Stops running containers without removing them. They can be started again with
Pauses running containers of a service. They can be unpaused with docker-compose unpause
Unpauses paused containers of a service.
Restarts all stopped and running services.
Only display IDs
Shows list of containers for a service.
Follow log output.
Displays log output from services.
View the processes running within each service container.
Pulls an image associated with a service defined in a docker-compose.yml file, but does not start containers based on those images.
Removes stopped service containers.By default, anonymous volumes attached to containers are not removed. You can override this with -v. To list all volumes, use docker volume ls.
-f, --force – Don’t ask to confirm the removal
-s, --stop – Stop the containers, if required, before removing
-v – Remove any anonymous volumes attached to containers
# makes the
db service available as the hostname
# (implies depends_on)
# make sure
db is alive before starting
# creates a custom network called
docker compose up
docker-compose -f <filename.yml> -f <filenamelocal.yml> up
use custom yml files
background detached mode
forcefully Build images before starting containers.
skips the image build process
Recreate containers even if their configuration and image haven’t changed.
Produce monochrome output.
Scale SERVICE to NUM instances. Overrides the
scale setting in the Compose file if present.
docker-compose up is used to start a project. It tries to automate a series of operations including building a mirror, (re)creating a service, starting a service, and associating a service-related container.
It also builds the images if the images do not exist and starts the containers:
Stops containers and removes containers, networks, volumes, and images
By default, the only things removed are:
- Containers for services defined in the Compose file
- Networks defined in the
networks section of the Compose file
- The default network, if one is used
up.Networks and volumes defined as
external are never removed.
use -v to remove volumes also along with other things
only builds the images, does not start the containers:
Runs a one-time command against a service. For example, the following command starts the web service and runs bash as its command :
docker-compose run wordpress_db bash
Prints the version of docker-compose.
Pushes images for services to their respective registry/repository
Validate and view the Compose file.
Forces running containers to stop by sending a SIGKILL signal.
A Dockerfile can be built into an image, and containers can be created from that image. Similarly, a docker-compose.yml can be built into a distributed application bundle
# build from Dockerfile
# build from custom Dockerfile
# build from image
- "8000:80" # guest:host
# expose ports to linked services (not to host)
# command to execute
command: bundle exec thin -p 3000
command: [bundle, exec, thin, -p, 3000]
# override the entrypoint
entrypoint: [php, -d, vendor/bin/phpunit]
# environment vars
# environment vars from file
env_file: [.env, .development.env]