For the time being, the goal is to be able to create a development environment, and it is not intended for production operation using docker.
Specifically, run tomcat8 on docker in the local development environment, The goal is to deploy war for webapp from IDE etc. and check the operation.
In addition, the explanation of the installation procedure such as docker for mac, docker command, docker-compose command required for these operations is omitted.
This time, we will do the following two things.
I will explain about deploying web applications next time.
--docker for mac (application) --docker-compose (command) --Use it because it is convenient to pass various parameters to the docker container. --Install with brew
docker version
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Tue Mar 28 00:40:02 2017
OS/Arch: darwin/amd64
Server:
Version: 17.03.1-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: c6d412e
Built: Fri Mar 24 00:00:50 2017
OS/Arch: linux/amd64
Experimental: true
docker-compose --version
docker-compose version 1.11.2, build dfed245
https://github.com/codekitchen/dinghy-http-proxy
This is a reverse proxy and DNS server for docker environment. If you put this in and set it, you will be able to access the tomcat container in the docker environment with the URL http://tomcat.docker/. It's easy to understand.
docker run -d --restart=always \
-v /var/run/docker.sock:/tmp/docker.sock:ro \
-v ~/.dinghy/certs:/etc/nginx/certs \
-p 80:80 -p 443:443 -p 19322:19322/udp \
-e DNS_IP=127.0.0.1 -e CONTAINER_NAME=http-proxy \
--name http-proxy \
codekitchen/dinghy-http-proxy
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96067c3ea144 codekitchen/dinghy-http-proxy "/app/docker-entry..." 47 seconds ago Up 45 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 19322/tcp, 0.0.0.0:19322->19322/udp http-proxy
Create a file named "docker" in / etc / resolver /
and
Please describe the following contents.
Now when there is a docker domain query, the query will go to the dinghy-http-proxy DNS server.
nameserver 127.0.0.1
port 19322
docker run -it --name testphp --expose 80 --env VIRTUAL_HOST=testphp.docker php php -S 0.0.0.0:80
Try accessing testphp.docker in your browser and It's OK if the log appears on the console.
PHP 7.1.3 Development Server started at Sat Apr 15 02:53:30 2017
Listening on http://0.0.0.0:80
Document root is /
Press Ctrl-C to quit.
[Sat Apr 15 02:53:44 2017] 172.17.0.2:40528 [404]: / - No such file or directory
[Sat Apr 15 02:53:45 2017] 172.17.0.2:40530 [404]: /favicon.ico - No such file or directory
After checking, send CTRL-C to the console that started php to exit.
The container used for confirmation is also unnecessary, so delete it.
docker rm testphp
Create an empty directory and create the following docker-compose.yml file in it.
docker-compose.yml
tomcat:
image: tomcat:8.0-jre8
ports:
- "8000:8000"
- "9090:9090"
environment:
VIRTUAL_HOST: tomcat.docker
VIRTUAL_PORT: 8080
CATALINA_OPTS: "-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9090
-Dcom.sun.management.jmxremote.rmi.port=9090
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=tomcat.docker"
command: catalina.sh jpda run
9090 is a JMX connection port, 8000 is the port for connecting to the debugger (JPDA). Since the 8080 port connects via dinghy-http-proxy, it is not necessary to specify publicity in ports.
The environment variables VIRTUAL_HOST and VIRTUAL_PORT are settings for dinghy-http-proxy. Now when you open http://tomcat.docker/ in your browser from mac It connects to port 8080 of the docker container.
Move to the same directory as docker-compose.yml and execute the following command to start the tomcat8 container.
docker-compose up
Starting tomcat8docker_tomcat_1
Attaching to tomcat8docker_tomcat_1
tomcat_1 | Listening for transport dt_socket at address: 8000
tomcat_1 | 15-Apr-2017 03:39:25.168 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.43
tomcat_1 | 15-Apr-2017 03:39:25.173 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Mar 28 2017 14:42:59 UTC
tomcat_1 | 15-Apr-2017 03:39:25.174 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.43.0
tomcat_1 | 15-Apr-2017 03:39:25.175 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
tomcat_1 | 15-Apr-2017 03:39:25.175 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.9.13-moby
tomcat_1 | 15-Apr-2017 03:39:25.177 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
tomcat_1 | 15-Apr-2017 03:39:25.177 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-8-openjdk-amd64/jre
tomcat_1 | 15-Apr-2017 03:39:25.178 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_121-8u121-b13-1~bpo8+1-b13
tomcat_1 | 15-Apr-2017 03:39:25.182 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
tomcat_1 | 15-Apr-2017 03:39:25.182 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat
tomcat_1 | 15-Apr-2017 03:39:25.183 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat
tomcat_1 | 15-Apr-2017 03:39:25.190 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
tomcat_1 | 15-Apr-2017 03:39:25.192 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
tomcat_1 | 15-Apr-2017 03:39:25.193 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
tomcat_1 | 15-Apr-2017 03:39:25.194 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
tomcat_1 | 15-Apr-2017 03:39:25.196 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_socket,address=localhost:8000,server=y,suspend=n
tomcat_1 | 15-Apr-2017 03:39:25.197 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote
tomcat_1 | 15-Apr-2017 03:39:25.198 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=9090
tomcat_1 | 15-Apr-2017 03:39:25.200 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.rmi.port=9090
tomcat_1 | 15-Apr-2017 03:39:25.201 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
tomcat_1 | 15-Apr-2017 03:39:25.202 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.local.only=false
tomcat_1 | 15-Apr-2017 03:39:25.202 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
tomcat_1 | 15-Apr-2017 03:39:25.204 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=tomcat.docker
tomcat_1 | 15-Apr-2017 03:39:25.205 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=/usr/local/tomcat/endorsed
tomcat_1 | 15-Apr-2017 03:39:25.206 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
tomcat_1 | 15-Apr-2017 03:39:25.206 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
tomcat_1 | 15-Apr-2017 03:39:25.208 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
tomcat_1 | 15-Apr-2017 03:39:25.211 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.12 using APR version 1.5.1.
tomcat_1 | 15-Apr-2017 03:39:25.212 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
tomcat_1 | 15-Apr-2017 03:39:25.224 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.1.0e 16 Feb 2017)
tomcat_1 | 15-Apr-2017 03:39:25.402 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
tomcat_1 | 15-Apr-2017 03:39:25.428 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
tomcat_1 | 15-Apr-2017 03:39:25.434 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 785 ms
tomcat_1 | 15-Apr-2017 03:39:25.494 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
tomcat_1 | 15-Apr-2017 03:39:25.504 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.43
tomcat_1 | 15-Apr-2017 03:39:25.527 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/host-manager
tomcat_1 | 15-Apr-2017 03:39:26.172 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/host-manager has finished in 645 ms
tomcat_1 | 15-Apr-2017 03:39:26.175 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/ROOT
tomcat_1 | 15-Apr-2017 03:39:26.227 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/ROOT has finished in 52 ms
tomcat_1 | 15-Apr-2017 03:39:26.230 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/manager
tomcat_1 | 15-Apr-2017 03:39:26.293 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/manager has finished in 63 ms
tomcat_1 | 15-Apr-2017 03:39:26.294 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs
tomcat_1 | 15-Apr-2017 03:39:26.353 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 60 ms
tomcat_1 | 15-Apr-2017 03:39:26.355 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
tomcat_1 | 15-Apr-2017 03:39:26.700 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 345 ms
tomcat_1 | 15-Apr-2017 03:39:26.707 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
tomcat_1 | 15-Apr-2017 03:39:26.728 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
tomcat_1 | 15-Apr-2017 03:39:26.752 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1317 ms
Try to display the following URL in your browser.
http://tomcat.docker/
Did you see the tomcat welcome page?
jconsole tomcat.docker:9090
Did you check the memory usage status with jconsole?
The following two system properties are important:
I referred to the following article. http://d.hatena.ne.jp/Kazuhira/20141112/1415782056
com.sun.management.jmxremote.rmi.port
JMX remote connection uses two port numbers, and one of them has an undefined port number, so if there is a firewall etc., it was not possible to connect before java7update4.
Basically, docker can not connect unless you explicitly specify the port and publish it, so Specify this property to fix the port used for JMX connection, and then You need to map that port and expose it to the mac side.
I referred to the following article. http://tech.furyu.jp/blog/?p=3467
java.rmi.server.hostname
https://ptmccarthy.github.io/2014/07/24/remote-jmx-with-docker/
And
https://forums.docker.com/t/enable-jmx-rmi-access-to-a-docker-container/625
According to the JavaVM startup system property java.rmi.server.hostname
It seems that you should set the IP address of docker in.
In this case, since docker is running on the local machine, it is OK if you specify 127.0.0.1
,
Even if you specify tomcat.docker
, it will be converted to 127.0.0.1 by DNS query, so it seems that either one is fine.
Recommended Posts