0

I don't know how to deploying the war file into tomcat 7 with the help of docker container.

It is easy in windows OS because we manually paste our project's war file into webapps folder of tomcat, but in case of docker container it is little bit difficult.

I don't know how to change port of tomcat and add role manager in tomcat-users.xml file in docker because of directory structure of docker container. and how to start tomcat using newly change port number in docker.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
jitendra korde
  • 445
  • 1
  • 6
  • 11
  • 1
    Possible duplicate of [Copying files from host to Docker container](https://stackoverflow.com/questions/22907231/copying-files-from-host-to-docker-container) – Alessandro Da Rugna Sep 05 '17 at 10:52

2 Answers2

4

The easiest way is to use the volume parameter (-v) with docker run to have the webapps directory and tomcat-users.xml file stay on the host filesystem, not on the container one.

For instance, on a Linux host:

  • create a file named /tmp/tomcat-users.xml with the correct content for your needs;
  • Then, create an empty directory named /tmp/webapps.

Now, run your container this way:

docker run -it --rm -p 8888:8080 -v /tmp/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml:ro -v /tmp/webapps:/usr/local/tomcat/webapps:rw tomcat:7

Then, since the container is started in foreground, connect to another shell (another window) and copy your war file into /tmp/webapps. It will be automatically deployed.

For instance, on a Windows host:

  • create a file named c:\tmp\tomcat-users.xml with the correct content for your needs;
  • Then, create an empty directory named c:\tmp\webapps.

Now, run your container this way:

docker run -it --rm -p 8888:8080 -v //c/tmp/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml:ro -v //c/tmp/webapps:/usr/local/tomcat/webapps:rw tomcat:7

Then copy your war file into c:\tmp\webapps. It will be automatically deployed.

Alexandre Fenyo
  • 4,526
  • 1
  • 17
  • 24
  • I've added an example in my answer. – Alexandre Fenyo Sep 05 '17 at 10:58
  • oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/D/tmp/tomcat-users.xml\\\" to rootfs \\\"/var/lib/docker/overlay2/a22ecafd3331690eacc04e8a5f54e7839bae9b0cc9cc71f020d4add2ff/merged\\\" at \\\"/var/lib/docker/overlay2/a22ecafd3331690eacc04e6df73b8a5f54e7839bae9b0cc9cc71f020d4add2ff/merged/usr/local/tomcat/conf/tomcat-users.xml\\\" caused \\\"not a directory\\\"\"" : Are you trying to mount a directory onto a file (or vice-versa)? Check if specified host path exists and is expected type. – jitendra korde Sep 05 '17 at 11:26
  • OK, I've updated the answer for docker on Windows hosts. – Alexandre Fenyo Sep 05 '17 at 11:33
  • i follow step given by you but in browser tomcat cannot start.it is started when i run above command using port 8830. it also show deployment message in command prompt – jitendra korde Sep 05 '17 at 11:53
  • in command prompt it show Deployment of web application archive /usr/local/tomcat/webapps/newihexa.war has finished in 48,708 ms this message means it deploy successfully but problem occure in browser with url:- localhost:8830 it doest not show tomcat homepage – jitendra korde Sep 05 '17 at 11:59
  • If you want the tomcat administration interface, you need to add the war file or directory in the directory c:\tmp\deploy. The tomcat administration interface is a war application like any other. – Alexandre Fenyo Sep 05 '17 at 12:02
  • [localhost-startStop-1] ERROR org.hibernate.util.JDBCExceptionReporter - Cannot create PoolableConnectionFactory this error message occurs. thanks in advanced @alexandre – jitendra korde Sep 05 '17 at 12:02
  • This may be explained because you use a DNS name to connect to the database and the container does not know the associated IP address. Use IP address to check if this is the problem. – Alexandre Fenyo Sep 05 '17 at 12:04
  • thank you very much finally it completed my task again thank you @alexandre – jitendra korde Sep 05 '17 at 12:24
0

As for March 2021, using a single command line solution on a Windows Docker, try this:

docker run --name YourApp -v "c/WarFiles/YourApp.war:/usr/local/tomcat/webapps/YourApp.war" -it -p 9090:8080 tomcat:7

Then open your app at http://localhost:9090/YourApp

Note "double quote" in volume and c drive with "Linux" slash / in order to make it work.

David
  • 109
  • 2
  • 9