Home > other >  Docker container problem of the Internet
Docker container problem of the Internet

Time:09-22

Now environment is such, join said I have two service, on a single host
A container as a tomcat, there is a Java web applications,
Another container as mysql, inside run data storage services,

Then start two containers
First is the mysql: docker run - d - name - v fdsafas:/fdsafa mysqlserver image_id
Then the tomcat: docker run - d - link mysqlserver: db -p 80:8080 - v fdsafsa:/fdsafjsad image_tomcat_id

Now I want to in a Java program database operation, such as Ip and port is to specify a database before, and then connect,

Now my idea is that if in a production environment, don't know the IP address of the container to mysql, how to connect?

Don't need to make a Java program to read the system environment variables? Because in tomcat container environment variables can actually see the mysql exposed the port number, such as:

 [root @ dockertest containers] # docker run - it - link mysqlserver: db - p, 80:80 - v/some/the content:/usr/share/nginx/HTML 5135500 ec6a1 env 
The Usage of loopback devices is strongly discouraged for production use. Either use ` - storage - opt dm. Thinpooldev ` or use ` - storage - opt dm. No_warn_on_loop_devices=true ` to suppress this warning.
PATH=/usr/local/sbin,/usr/local/bin:/usr/sbin,/usr/bin:/sbin/bin:
The HOSTNAME=8 b91ed33f8fd
The TERM=xterm
DB_PORT=TCP://172.17.0.2:3306
DB_PORT_3306_TCP=TCP://172.17.0.2:3306
DB_PORT_3306_TCP_ADDR=172.17.0.2
DB_PORT_3306_TCP_PORT=3306
DB_PORT_3306_TCP_PROTO=TCP
DB_NAME=/lonely_pasteur/db

CodePudding user response:

Consult! Hope someone answer

CodePudding user response:

First set the IP address of the container into a static, then on the hosts and set into a domain name, and then write a shell script, if the container after the restart, preventing IP address change, if you have other questions, please join the docker new group of 397201742

CodePudding user response:

I think the link through the can;

CodePudding user response:

Use -.net=host can see IP host machine in the container

CodePudding user response:

Into a static address, access is directly from the address, they are in the same IP in the class,

CodePudding user response:

Mysql port is mapped to the host machine, and then by modifying the/etc/hosts file of the host machine, javaweb that container can be through the domain name to connect to mysql

CodePudding user response:

The
reference 3 floor u014013026 response:
I think the link through the can;
can use alias
  • Related