1, create a java image:
Put all the files in the docker directory and create different directories for different functions.
$ sudo mkdir docker/java
$ sudo cd docker/java
Next, create a Dockerfile file of jdk in this directory, and the details are as follows:
# openjdk 6
# Version 1.0
From ubuntu: 14.04
Maintainer mhy "mhy2011@ gmail.com"
Run apt-get update
Run apt-get install-y-q open JDK-7-JDK.
Work direction/
ENV JAVA _ HOME/usr/lib/JVM/JAVA-7-open JDK-amd64
CMD ["/bin/bash"]
Create a mirror image of jdk after creating Dockerfile.
$ sudo docker build -t pobaby/java。
You can see that an image named pobaby/java has been generated. Next, check whether the image can be used normally, start a container through the image, and then see if the java command can be executed.
2. Create a resin image.
The webserver used here is resin, not tomcat:
Use the pobaby/java image just created as the base image to create a resin image.
# resin
# Version 1.0
From pobaby/java
Maintainer mhy "mhy2011@ gmail.com"
Run apt-get update
Add resin-3.1.14. tar.gz/opt/
Working Directory/Options/
Run mv resin -3. 1. 14 resin.
Exposure 8080
Entry point ["/opt/resin/bin/httpd.sh"]
There is a line in this file.
Add resin-3.1.14. tar.gz/opt/
That is, add resin-3.1.14. tar.gz in the current directory to the /opt/ directory of the container and decompress it. Of course, it can also be downloaded from the internet.
Next, a mirror image containing resin is generated.
$ sudo docker build-t po baby/ resin.
Another mirror named pobaby/resin is generated here. Next, start a container through this image to see if the environment is normal.
$ sudo docker run-d-p 80:8080-name web 00 1 po baby/resin
3. Next, access the container and map local port 80 to container port 8080.
4. start the Web project.
Create a basic image containing a web server, then start a container and mount the local web application when starting the container, as shown below:
$ sudo docker run-d-p 888 1:8080-name we B- demo-v $ PWD/web apps:/opt/resin/web apps po baby/resin
A container named web-demo is started above, and the project web-demo under webapps is mounted in the container /opt/resin/webapps.
The results of this visit are as follows:
A simple Java Web program based on Docker container is implemented above.