Home > Article > Development Tools > docker-compose command comparison
The following column composer tutorial will introduce you to the comparison of docker-compose commands. I hope it will be helpful to friends in need!
Comparison
image vs build
#image: If the image is not available locally exists, Compose will try to pull this image.
build: Specify the path to the folder where Dockerfile is located. Compose will use this to automatically build the image and then use the image.
● links vs external_links
links: Links to containers in other services. Either the service name (which also serves as an alias) or the service name: service alias (SERVICE:ALIAS) format is acceptable. The alias used will be automatically created in /etc/hosts in the service container.
external_links: Links to containers outside docker-compose.yml, even containers that are not managed by Compose.
ports vs expose
● ports
Expose port information. You can use the HOST:CONTAINER format or just specify the port of the container (the host will randomly select the port).
When using the HOST:CONTAINER format to map ports, if the container port you use is less than 60 you may get incorrect results because YAML will parse the xx:yy number format as base 60. So it is recommended to use string format.
● expose
Expose the port, but it is not mapped to the host and is only accessed by the connected service.
Only the internal port can be specified as the parameter
volumes vs volumes_from
● volumes
Volume mount path setting. You can set the host path (HOST:CONTAINER) or add the access mode (HOST:CONTAINER:ro).
ro means readonly, read-only mode.
● volumes_from
Mount all its volumes from another service or container.
Note:
Compose environment variable description Environment variables are no longer the recommended method for connecting to services. Instead, the link name (the name of the linked service by default) should be used as Host name to connect to, see docker-compose.yml for more details. Compose uses Docker links to expose service containers to others. Each linked container uses a set of environment variables, each of which begins with a capital letter of the container name. To view the environment variables available to a service, run docker-compose run SERVICE env
The above is the detailed content of docker-compose command comparison. For more information, please follow other related articles on the PHP Chinese website!