Detailed explanation:
version: '3' #Compose file versions support a particular version of Docker services: # service configuration list of the project swapping: #spring boot service name, service name, custom container_name: swapping-compose # Name container instance this spring to start the service after boot, if specified, in accordance with the naming container if not specified, the vessel is naming # [[Compose file directory] _ [service name] _1], [such as] swappingdockercompose_swapping_1 # If the multi-boot, which is docker-compose scale swapping = 3 mysql = 2, then there is no need to specify the name of the vessel, otherwise it will error vessel name repeated problems build: # Based on property use when building the image of Dockerfile file context:. # represents the current directory, you can also specify an absolute path [/ path / test / Dockerfile] or relative path [../test/Dockerfile], as far as possible in the current directory, easy to manage dockerfile: Dockerfile-swapping # Dockerfile specify the file name. If the context specified file name, where this would not attribute the ports: # alluding Port Properties - "9666: 9666" # recommended format string that specifies the host port mapped to a port of the container volumes: # Mount Properties - .:/vol/development # Mount only the specified directory path in the container compose the configuration file, and docker run command to specify [host directory: a container directory] type of mount. Can be used: ro the read-only directory of the container to protect the host file system depends_on: # This service starts, which need to rely on other services such as here; mysql service will be started in swapping service. As for a plurality of words, a plurality of inner-dependent promoter sequence untested depends_on - mysql links: # depends_on corresponds with the above control of a promoter sequence, a container connected to the control problem. - "mysql: mysql" # value can be - mysql [- service name], it can be - "mysql: mysql" [- "Service: Alias"] restart: always # whether to restart the service starts with the docker networks: # join the specified network - my-network # custom network name environment: #environment Dockerfile and the ENV variable will have the same instruction stored in the mirror, a container, a similar effect docker run -e. Set the environment variable container - TZ = Asia / Shanghai # here to set the time zone for the container Asia Shanghai, will solve the problem of time zones vessel started by compose choreography! ! ! ! Solve the problem of time zones vessel! ! ! mysql: # service named mysql, custom container_name: mysql-compose # container name image: mysql: 5.7 # Although there is no use build, but the use of the image, is specified based on mysql: the basis to construct a mirror image mirror 5.7. Usage-based Dockerfile build file to build, Dockerfile file is also based on the base image] FROM ports: - "33061:3306" command: [# Use command can override the default command is executed after the vessel started '--Character-set-server = utf8mb4', # set the database table data set '--Collation-server = utf8mb4_unicode_ci', # set the database table data set '--Default-time-zone = + 8: 00' # Set time zone issues mysql database! ! ! ! Instead of setting the time zone of the container problem! ! ! ! ] environment: MYSQL_DATABASE: swapping # Set the initial database name MYSQL_ROOT_PASSWORD: 398023 # set the root password connection MYSQL_ROOT_HOST: '%' restart: always networks: - my-network networks: # compose detailed use on the networks of https://blog.csdn.net/Kiloveyousmile/article/details/79830810 my-network: # custom network will create a custom build a network for the first time, the default is the bridge
This table shows which Compose file versions support a particular version of Docker. Reference: https://docs.docker.com/compose/compose-file/
references
https://www.cnblogs.com/sxdcgaq8080/p/10072040.html
https://docs.docker.com/compose/overview/ official documents