web123456

Use of volumes, environment, privileged, network_mode in docker-compose

  • privileged: used to give root permissions to containers, unsafe
  • environment: Set environment variables in container
  • volumes: used to store docker persisted data. After starting the tomcat container, the file package in the host directory is read.
  • network_mode: Set the network mode of the container. The following are several network modes. If you need it, you can search for information by yourself.
    1. host: The container environment is not isolated, the host's port and IP will be used, and cannot be used at the same time as the ports port mapping.
    2. bridge
    3. overlay
    4. Macvlan

The following are the usage of these parameters

tomcat:
  restart: always
  image: tomcat:latest
  container_name: tomcat
  network_mode: host//Set the network mode to host mode
   Volumes:
     - ~/java:/usr/local/tomcat/webapps/ //mount the ~/java/ directory in the host to the directory where to store the war package in the container
   environment:
     LOGONAME: tomcat //Set environment variables in tomcat
   privileged:true//Set the permissions of the container to root