I am trying to test and use docker for my environment. Here is my Dockerfile When I access the tomcat ( http://localhost:8080
), I get the problem This site can't be reached
.
Note => For window, I use http://192.168.99.100:8080/
.
Build
docker build -f Dockerfile -t docker-spring-rest .
Run
docker run -p 8080:8080 -p 3306:3306 docker-spring-rest
Dockerfile
#Prat-1 tomcat
FROM tomcat:8.5.35
COPY ./target/spring-rest.war /usr/local/tomcat/webapps/
EXPOSE 8080
#Prat-1 tomcat
FROM mysql:5.5
ENV MYSQL_ROOT_PASSWORD root
ENV MYSQL_DATABASE spring-rest
COPY ./DB.SQL /docker-entrypoint-initdb.d/
One strange thing is, If I setup only Part-1 tomcat
without mysql
, I can access http://192.168.99.100:8080/
or my application http://192.168.99.100:8080/spring-rest
Is there any missing in my file?
Googling => I checked this tomcat-mysql reference. Why they use apt-get
to install because of docker already have multiple images? Can I use multiple FROM
like FROM tomcat, FROM mysql, FROM xxx
in single Dockerfile
?
The key question is here: "Can I use multiple FROM
... in a single Dockerfile".
If you do that, you are using a new docker feature called multistage-build . This feature allows you to build an image in multiple stages, where each FROM
starts from a fresh base layer, discarding everything you did before .
This is not what you intent to do, because when you do FROM mysql:5.5
you loose the entire tomcat part from above that line.
You could build a docker image containing tomcat and mysql (using only one FROM
) instruction, but I would advised against it. Docker images are supposed to deal with one concern only .
So indeed the best solution would be to create two Docker images (2 Dockerfiles), one for tomcat, one for mysql and then use docker-compose to run the two as a composite.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.